[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip SNMP.java,1.3,1.4
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2005-12-04 23:11:03
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5085/core/protocolsuite/tcp_ip Modified Files: SNMP.java Log Message: Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SNMP.java 4 Dec 2005 00:47:55 -0000 1.3 --- SNMP.java 4 Dec 2005 23:10:54 -0000 1.4 *************** *** 48,55 **** public class SNMP extends Application{ ! protected static int SNMPID = 0; public SNMP(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); } /** --- 48,66 ---- public class SNMP extends Application{ ! private static int SNMPID = 0; ! private static Vector<SNMPInstance> SNMPgroups; public SNMP(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); + //groups and instance required placed in lexicographical order :(MIB) + int i; + SNMPgroups.add(new SNMPInstance("SNMP")); + i=SNMPgroups.size()-1; + SNMPgroups.get(i).add("revision","0"); + SNMPgroups.get(i).add("version","2"); + SNMPgroups.add(new SNMPInstance("test")); + i=SNMPgroups.size()-1; + SNMPgroups.get(i).add("test_1","A"); + SNMPgroups.get(i).add("test_2","1"); } /** *************** *** 121,166 **** } public void GetRequest(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPMessage(0,"public",0,getNextID(),0,0,r); SendData(pack); } public void GetNextRequest(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPMessage(1,"public",0,getNextID(),0,0,r); SendData(pack); } ! public void SetRequest(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPMessage(2,"public",0,getNextID(),0,0,r); SendData(pack); } ! public void GetResponse(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPMessage(3,"public",0,getNextID(),0,0,r); SendData(pack); } ! public void Trap(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { } ! protected static String CreateSNMPMessage(int ver,String pass,int type,int id,int er,int erindex,Vector<String> r) { ! String s; ! char c; ! char[] ac=new char[2]; ! int sizepack=0,sizedata=0; ! ac[0]=0xA5; ac[1]=0x82; ! s=String.copyValueOf(ac); - return s; } protected static boolean ParseSNMPMessage(int ver,String pass,int type,int id,int er,int erindex,Vector<String> r) { ! String s; ! s = String.valueOf(ver)+pass+String.valueOf(type)+String.valueOf(id)+String.valueOf(er)+String.valueOf(erindex); return true; } protected static int getNextID() { if(SNMPID>=65535) SNMPID=0; --- 132,248 ---- } + /** + * This method realize Get-request function of SNMPv2. + * @param r vector of String. String as 'group.instance' + * @author QweR + * @version v0.01 + */ public void GetRequest(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPHeader(getNextID(),0); SendData(pack); } + /** + * This method realize Get-next-request function of SNMPv2. + * @param r vector of String. String as 'group.instance' + * @author QweR + * @version v0.01 + */ public void GetNextRequest(Vector<String> r) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPHeader(getNextID(),1); SendData(pack); } ! /** ! * This method realize Set-request function of SNMPv2. ! * @param r vector of String. String as 'group.instance' ! * @param v vector of String. String as 'value' ! * @author QweR ! * @version v0.01 ! */ ! public void SetRequest(Vector<String> r,Vector<String> v) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPHeader(getNextID(),2); SendData(pack); } ! /** ! * This method realize Get-response function of SNMPv2. ! * @param r vector of String. String as 'group.instance' ! * @param v vector of String. String as 'value' ! * @author QweR ! * @version v0.01 ! */ ! public void GetResponse(Vector<String> r,Vector<String> v) throws LowLinkException, TransportLayerException, CommunicationException { ! String pack = CreateSNMPHeader(getNextID(),3); SendData(pack); } ! /** ! * This method realize TRAP function of SNMPv2. ! * @param r vector of String. String as 'group.instance' ! * @param v vector of String. String as 'value' ! * @author QweR ! * @version v0.01 ! */ ! public void Trap(Vector<String> r,Vector<String> v) throws LowLinkException, TransportLayerException, CommunicationException { } ! /** ! * This method create a SNMP header for all type packets. ! * @param Data to recv ! * @author QweR ! * @version v0.01 ! */ ! protected static String CreateSNMPHeader(int id,int type) { ! char[] c = new char[8]; ! c[0]=c[1]=0; ! c[2]=2; ! c[3]=2; ! c[4]=0; ! c[5]=(char)(id/256); ! c[6]=(char)(id%256); ! c[7]=(char)type; ! return (String.copyValueOf(c)); ! } ! ! /** ! * This method recieves data from the other side. ! * @param Data to recv ! * @author QweR ! * @version v0.01 ! */ ! protected static String CreateSNMPVars(Vector<String> r) { ! ! } ! ! /** ! * This method recieves data from the other side. ! * @param Data to recv ! * @author QweR ! * @version v0.01 ! */ ! protected static String CreateSNMPVarsValue(Vector<String> r,Vector<String> v) { } + /** + * This method parse incomimg packet and return readable data. + * @param Data to recv + * @author QweR + * @version v0.01 + */ protected static boolean ParseSNMPMessage(int ver,String pass,int type,int id,int er,int erindex,Vector<String> r) { ! return true; } + /** + * This method gets next value of SNMPID modulo 2^16. + * @param Data to recv + * @author QweR + * @version v0.01 + */ protected static int getNextID() { if(SNMPID>=65535) SNMPID=0; *************** *** 168,170 **** --- 250,287 ---- return SNMPID; } + + public static int getGroupID(String n) { + int i; + + for(i=0;i<SNMPgroups.size();i++) { + if(SNMPgroups.get(i).name.compareTo(n)==0) break; + } + if(i>=SNMPgroups.size()) return (-1); + return i; + } + + public class SNMPInstance { + public String name; + public Vector<String> instance = new Vector<String>(0); + public Vector<String> value = new Vector<String>(0); + + public SNMPInstance(String n) { + name=n; + } + + public int getInstanceID(String n) { + int i; + + for(i=0;i<instance.size();i++) { + if(instance.get(i).compareTo(n)==0) break; + } + if(i>=instance.size()) return (-1); + return i; + } + + public void add(String i,String v) { + instance.add(i); + value.add(v); + } + } } |