KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > SnmpFrameworkMIB


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SnmpFrameworkMIB.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent.mo.snmp;
23
24 import org.snmp4j.agent.MOGroup;
25 import org.snmp4j.agent.MOServer;
26 import org.snmp4j.smi.OctetString;
27 import org.snmp4j.agent.DuplicateRegistrationException;
28 import org.snmp4j.agent.mo.MOScalar;
29 import org.snmp4j.agent.mo.MOAccessImpl;
30 import org.snmp4j.smi.OID;
31 import org.snmp4j.smi.Variable;
32 import org.snmp4j.smi.Integer32;
33 import java.util.Iterator JavaDoc;
34 import org.snmp4j.TransportMapping;
35 import java.util.Collection JavaDoc;
36 import org.snmp4j.security.USM;
37
38 public class SnmpFrameworkMIB implements MOGroup {
39
40   private USM usm;
41   private Collection JavaDoc transportMappings;
42
43   private MOScalar snmpEngineID;
44   private MOScalar snmpEngineBoots;
45   private MOScalar snmpEngineTime;
46   private MOScalar snmpEngineMaxMessageSize;
47
48   public SnmpFrameworkMIB(USM usm, Collection JavaDoc transportMappings) {
49     this.usm = usm;
50     this.transportMappings = transportMappings;
51     createMOs();
52   }
53
54   private void createMOs() {
55     snmpEngineID = new MOScalar(new OID("1.3.6.1.6.3.10.2.1.1.0"),
56                                 MOAccessImpl.ACCESS_READ_ONLY,
57                                 null) {
58       public Variable getValue() {
59         return new OctetString(getUSM().getLocalEngineID());
60       }
61     };
62     snmpEngineBoots = new MOScalar(new OID("1.3.6.1.6.3.10.2.1.2.0"),
63                                    MOAccessImpl.ACCESS_READ_ONLY,
64                                    null) {
65       public Variable getValue() {
66         return new Integer32(getUSM().getEngineBoots());
67       }
68     };
69     snmpEngineTime = new MOScalar(new OID("1.3.6.1.6.3.10.2.1.3.0"),
70                                   MOAccessImpl.ACCESS_READ_ONLY,
71                                   null) {
72       public Variable getValue() {
73         return new Integer32(getUSM().getEngineTime());
74       }
75     };
76     Integer32 maxMsgSize = new Integer32(getMaxMessageSize());
77     snmpEngineMaxMessageSize = new MOScalar(new OID("1.3.6.1.6.3.10.2.1.4.0"),
78                                             MOAccessImpl.ACCESS_READ_ONLY,
79                                             maxMsgSize);
80   }
81
82   private int getMaxMessageSize() {
83     int totalMaxMessageSize = 2147483647;
84     for (Iterator JavaDoc it = transportMappings.iterator();
85          it.hasNext();) {
86       int maxMsgSize = ((TransportMapping)it.next()).getMaxInboundMessageSize();
87       totalMaxMessageSize = Math.min(totalMaxMessageSize, maxMsgSize);
88     }
89     return totalMaxMessageSize;
90   }
91
92   public void registerMOs(MOServer server, OctetString context) throws
93       DuplicateRegistrationException {
94     if (usm != null) {
95       server.register(snmpEngineID, context);
96       server.register(snmpEngineBoots, context);
97       server.register(snmpEngineTime, context);
98     }
99     server.register(snmpEngineMaxMessageSize, context);
100   }
101
102   public void unregisterMOs(MOServer server, OctetString context) {
103     server.unregister(snmpEngineID, context);
104     server.unregister(snmpEngineBoots, context);
105     server.unregister(snmpEngineTime, context);
106     server.unregister(snmpEngineMaxMessageSize, context);
107   }
108
109   public MOScalar getSnmpEngineBoots() {
110     return snmpEngineBoots;
111   }
112
113   public MOScalar getSnmpEngineID() {
114     return snmpEngineID;
115   }
116
117   public MOScalar getSnmpEngineMaxMessageSize() {
118     return snmpEngineMaxMessageSize;
119   }
120
121   public MOScalar getSnmpEngineTime() {
122     return snmpEngineTime;
123   }
124
125   public USM getUSM() {
126     return usm;
127   }
128
129 }
130
Popular Tags