[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip SNMP.java,1.8,1.9
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-02-22 20:04:37
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3906/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.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SNMP.java 9 Feb 2006 23:12:39 -0000 1.8 --- SNMP.java 22 Feb 2006 20:04:27 -0000 1.9 *************** *** 37,41 **** --- 37,46 ---- import core.Packet; import core.Simulation; + import core.ApplicationLayerDevice; + import core.NetworkLayerDevice; + import core.Node; import java.util.Vector; + import java.lang.Integer; + import java.util.ArrayList; /** *************** *** 52,56 **** public final static int SNMP_ERROR_badValue = 3; // == SNMP_ERROR_wrongValue ??? public final static int SNMP_ERROR_readOnly = 4; ! public final static int SNMP_ERROR_gerErr = 5; public final static int SNMP_ERROR_noAccess = 6; public final static int SNMP_ERROR_wrongType = 7; --- 57,61 ---- public final static int SNMP_ERROR_badValue = 3; // == SNMP_ERROR_wrongValue ??? public final static int SNMP_ERROR_readOnly = 4; ! public final static int SNMP_ERROR_genErr = 5; public final static int SNMP_ERROR_noAccess = 6; public final static int SNMP_ERROR_wrongType = 7; *************** *** 66,69 **** --- 71,75 ---- private Vector<SNMPInstance> SNMPgroups = new Vector<SNMPInstance>(0); private String current_password = ""; + private ApplicationLayerDevice current_device; //following variables be actual temporality private int m_len=0; *************** *** 88,103 **** private Vector<String> tVectorString = new Vector<String>(0); ! 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"); } /** --- 94,136 ---- private Vector<String> tVectorString = new Vector<String>(0); ! public SNMP(ApplicationLayerDevice device,ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); + current_device = device; //groups and instance required placed in lexicographical order :(MIB) int i; ! SNMPgroups.add(new SNMPInstance("Counter")); //generate by SNMP manager (updateValues) i=SNMPgroups.size()-1; ! SNMPgroups.get(i).add("InputIP",""); //ro ! SNMPgroups.get(i).add("OutputIP",""); //ro ! SNMPgroups.get(i).add("ARP",""); //ro ! SNMPgroups.get(i).add("InputTCP",""); //ro ! SNMPgroups.get(i).add("OutputTCP",""); //ro ! SNMPgroups.get(i).add("ReceiveDuplicatedTCP",""); //ro ! SNMPgroups.get(i).add("SendDuplicatedTCP",""); //ro ! SNMPgroups.get(i).add("SendAckTCP",""); //ro ! SNMPgroups.get(i).add("InputUDP",""); //ro ! SNMPgroups.get(i).add("OutputUDP",""); //ro ! SNMPgroups.add(new SNMPInstance("Device")); //generate by SNMP manager (updateValues) i=SNMPgroups.size()-1; ! SNMPgroups.get(i).add("AllInterfaces",""); //ro ! SNMPgroups.get(i).add("AvailableInterfaces",""); //ro ! SNMPgroups.get(i).add("Hostname",""); //ro! ! SNMPgroups.get(i).add("MACaddress_Eth0",""); //ro ! SNMPgroups.add(new SNMPInstance("IP")); //generate by SNMP manager (updateValues) ! i=SNMPgroups.size()-1; ! SNMPgroups.get(i).add("AllInterfaces",""); //ro ! SNMPgroups.get(i).add("ARPTable",""); //ro ! SNMPgroups.get(i).add("DefaultGateway",""); //rw ! SNMPgroups.get(i).add("Address_Eth0",""); //rw ! SNMPgroups.get(i).add("SubnetMask_Eth0",""); //rw ! SNMPgroups.add(new SNMPInstance("SNMP")); //setup by developer ! i=SNMPgroups.size()-1; ! SNMPgroups.get(i).add("CommunityName",""); //rw ! SNMPgroups.get(i).add("revision","0"); //ro ! SNMPgroups.get(i).add("version","2"); //ro ! SNMPgroups.add(new SNMPInstance("test")); //temporary test MIB ! i=SNMPgroups.size()-1; ! SNMPgroups.get(i).add("test_1","A"); //rw ! SNMPgroups.get(i).add("test_2","1"); //rw } /** *************** *** 191,195 **** try { if(parse(Data) == 0) { ! updateValues(); switch(m_type) { case SNMP_GET: { --- 224,228 ---- try { if(parse(Data) == 0) { ! updateMIBValues(); switch(m_type) { case SNMP_GET: { *************** *** 197,202 **** printInfo("Received getRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! getValues(); ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); } else { --- 230,237 ---- printInfo("Received getRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! if(getValues()) ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); // m_errorstatus == 0 && m_errorindex ==0 ! else ! getResponse(retIP, retPort, tVectorString, tVectorString, m_errorstatus, m_errorindex); } else { *************** *** 211,216 **** printInfo("Received getNextRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! getnextValues(); ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); } else { --- 246,253 ---- printInfo("Received getNextRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! if(getnextValues()) ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); // m_errorstatus == 0 && m_errorindex ==0 ! else ! getResponse(retIP, retPort, tVectorString, tVectorString, m_errorstatus, m_errorindex); } else { *************** *** 225,230 **** printInfo("Received setRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! setValues(); ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); } else { --- 262,269 ---- printInfo("Received setRequest: `" + getPacketData(lastPacket)+"`"); if(current_password.compareTo(m_password)==0) { ! if(setValues()) ! getResponse(retIP, retPort, m_vars, m_values, m_errorstatus, m_errorindex); // m_errorstatus == 0 && m_errorindex ==0 ! else ! getResponse(retIP, retPort, tVectorString, tVectorString, m_errorstatus, m_errorindex); } else { *************** *** 249,252 **** --- 288,333 ---- s+="'"+m_vars.get(i)+"="+m_values.get(i)+"'"; } + switch(m_errorstatus) { + case SNMP_ERROR_noError: { + //s+=" without error"; + break; + } + case SNMP_ERROR_noSuchName: { + s+=" no such name #"+Integer.valueOf(m_errorindex).toString(); + break; + } + case SNMP_ERROR_badValue: { + s+=" bad value #"+Integer.valueOf(m_errorindex).toString(); + break; + } + case SNMP_ERROR_readOnly: { + s+=" read only #"+Integer.valueOf(m_errorindex).toString(); + break; + } + case SNMP_ERROR_genErr: { + s+=" gereral error"; + break; + } + case SNMP_ERROR_noAccess: { + s+=" no access (incorrect community name)"; + break; + } + case SNMP_ERROR_wrongType: { + s+=" wrong type #"+Integer.valueOf(m_errorindex).toString(); + break; + } + case SNMP_ERROR_wrongLength: { + s+=" wrong length"; + break; + } + case SNMP_ERROR_wrongEncoding: { + s+=" wrong encoding"; + break; + } + case SNMP_ERROR_wrongValue: { + s+=" wrong value #"+Integer.valueOf(m_errorindex).toString(); + break; + } + } printInfo("Received getResponse: " + s); } *************** *** 261,266 **** } else { ! printInfo("Received corrupted packet!"); ! getResponse(retIP, retPort, tVectorString, tVectorString, m_errorstatus, m_errorindex); } if(appType==0) { --- 342,361 ---- } else { ! switch(appType) { ! case 0: { ! printInfo("Agent received corrupted packet!"); ! getResponse(retIP, retPort, tVectorString, tVectorString, m_errorstatus, m_errorindex); ! break; ! } ! case 1: { ! printInfo("Manager received corrupted packet!"); ! break; ! } ! default: { ! printInfo("UNKNOWN program received corrupted packet!"); ! break; ! } ! } ! } if(appType==0) { *************** *** 315,319 **** pack += createSNMPPassword(password); String tmp = createSNMPVars(r); ! if(tmp.compareTo("")==0) { return false; } --- 410,414 ---- pack += createSNMPPassword(password); String tmp = createSNMPVars(r); ! if(tmp==null) { return false; } *************** *** 342,346 **** pack += createSNMPPassword(password); String tmp = createSNMPVars(r); ! if(tmp.compareTo("")==0) { return false; } --- 437,441 ---- pack += createSNMPPassword(password); String tmp = createSNMPVars(r); ! if(tmp==null) { return false; } *************** *** 370,374 **** pack += createSNMPPassword(password); String tmp = createSNMPVarsValues(r,v); ! if(tmp.compareTo("")==0) { return false; } --- 465,469 ---- pack += createSNMPPassword(password); String tmp = createSNMPVarsValues(r,v); ! if(tmp==null) { return false; } *************** *** 396,400 **** pack += createSNMPError(es,ei); String tmp = createSNMPVarsValues(r,v); ! if(tmp.compareTo("")==0) { return false; } --- 491,495 ---- pack += createSNMPError(es,ei); String tmp = createSNMPVarsValues(r,v); ! if(tmp==null) { return false; } *************** *** 421,425 **** // pack += createSNMPTrap(gtc,stc); // String tmp = createSNMPVarsValues(r,v); ! // if(tmp.compareTo("")==0) { // return false; // } --- 516,520 ---- // pack += createSNMPTrap(gtc,stc); // String tmp = createSNMPVarsValues(r,v); ! // if(tmp==null) { // return false; // } *************** *** 534,544 **** /** * This method gets values from vector of 'group.instance'. ! * return if result equals zero then function successful complete ! * if result == 1 then invalid variable name (without dots). ! * if result == 2 then not found groupID or instanceID * @author QweR * @version v0.01 */ ! protected int getValues() { String[] a; int i; --- 629,637 ---- /** * This method gets values from vector of 'group.instance'. ! * return true if function successful complete. If function false then m_errorstatus & m_errorindex contain error code * @author QweR * @version v0.01 */ ! protected boolean getValues() { String[] a; int i; *************** *** 551,570 **** m_values.add(SNMPgroups.get(m_GroupID).value.get(m_InstanceID)); } ! else return 2; } - else return 1; } ! return 0; } /** * This method get next values from vector of 'group.instance'. ! * return if result equals zero then function successful complete ! * if result == 1 then invalid variable name (without dots). ! * if result == 2 then not found groupID or instanceID * @author QweR * @version v0.01 */ ! protected int getnextValues() { String[] a; int i; --- 644,669 ---- m_values.add(SNMPgroups.get(m_GroupID).value.get(m_InstanceID)); } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; ! } ! } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; } } ! return true; } /** * This method get next values from vector of 'group.instance'. ! * return true if function successful complete. If function false then m_errorstatus & m_errorindex contain error code * @author QweR * @version v0.01 */ ! protected boolean getnextValues() { String[] a; int i; *************** *** 580,601 **** m_vars.set(i,SNMPgroups.get(m_GroupID).name+"."+SNMPgroups.get(m_GroupID).instance.get(m_InstanceID)); } ! else return 2; } - else return 1; } ! return 0; } /** * This method sets values from vector of 'group.instance' and 'value'. ! * return if result equals zero then function successful complete ! * if result == 1 then invalid variable name (without dots) ! * if result == 2 then not found groupID or instanceID ! * if result == 3 then value of variable is incorrect * @author QweR * @version v0.01 */ ! protected int setValues() { String[] a; int i; int er; --- 679,706 ---- m_vars.set(i,SNMPgroups.get(m_GroupID).name+"."+SNMPgroups.get(m_GroupID).instance.get(m_InstanceID)); } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; ! } ! } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; } } ! return true; } /** * This method sets values from vector of 'group.instance' and 'value'. ! * return true if function successful complete. If function false then m_errorstatus & m_errorindex contain error code * @author QweR * @version v0.01 */ ! protected boolean setValues() { String[] a; + String[] sa = new String[m_vars.size()]; int i; int er; *************** *** 605,619 **** if(a.length>=2) { if(getIDbyName(a[0],a[1])) { ! er = checkValues(a[0]+"."+a[1], m_values.get(i)); if(er==0) { SNMPgroups.get(m_GroupID).value.set(m_InstanceID,m_values.get(i)); } - else return er; } ! else return SNMP_ERROR_noSuchName; } - else return SNMP_ERROR_noSuchName; } ! return 0; } --- 710,738 ---- if(a.length>=2) { if(getIDbyName(a[0],a[1])) { ! er = checkMIBValue(a[0]+"."+a[1], m_values.get(i)); if(er==0) { SNMPgroups.get(m_GroupID).value.set(m_InstanceID,m_values.get(i)); + sa[i] = a[0]+"."+a[1]; + } + else { + m_errorstatus = er; + m_errorindex = i+1; + return false; } } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; ! } ! } ! else { ! m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex = i+1; ! return false; } } ! for(i=0;i<m_vars.size();i++) setMIBValue(sa[i], m_values.get(i)); //set values only if all variables correct ! return true; } *************** *** 665,669 **** String[] gi; String out = ""; ! char[] c = new char[4]; for(i=0;i<r.size();i++) { --- 784,789 ---- String[] gi; String out = ""; ! char[] c = {0,0,0,0}; ! //char[] c = new char[4]; for(i=0;i<r.size();i++) { *************** *** 672,683 **** if(getIDbyName(gi[0], gi[1])) { c[0]=(char)(m_GroupID+1); ! c[1]=0; c[2]=(char)(m_InstanceID+1); ! c[3]=0; ! out+=String.copyValueOf(c); } ! else return ""; } ! else return ""; } return out; --- 792,803 ---- if(getIDbyName(gi[0], gi[1])) { c[0]=(char)(m_GroupID+1); ! //c[1]=0; c[2]=(char)(m_InstanceID+1); ! //c[3]=0; } ! else c[0]=c[2]=0; } ! else c[0]=c[2]=0; ! out+=String.copyValueOf(c); } return out; *************** *** 696,701 **** String[] gi; String out = ""; ! char[] c = new char[4]; ! char[] cv; if(r.size()!=v.size()) return ""; --- 816,821 ---- String[] gi; String out = ""; ! char[] c = {0,0,0,0}; ! char[] cv = new char[3]; if(r.size()!=v.size()) return ""; *************** *** 705,720 **** if(getIDbyName(gi[0],gi[1])) { c[0]=(char)(m_GroupID+1); ! c[1]=0; c[2]=(char)(m_InstanceID+1); ! c[3]=0; ! cv = new char[3]; ! cv[0]=2; ! cv[1]=(char)(v.get(i).length()/256); ! cv[2]=(char)(v.get(i).length()%256); ! out+=String.copyValueOf(c)+String.copyValueOf(cv)+v.get(i); } ! else return ""; } ! else return ""; } return out; --- 825,839 ---- if(getIDbyName(gi[0],gi[1])) { c[0]=(char)(m_GroupID+1); ! //c[1]=0; c[2]=(char)(m_InstanceID+1); ! //c[3]=0; } ! else c[0]=c[2]=0; } ! else c[0]=c[2]=0; ! cv[0]=2; ! cv[1]=(char)(v.get(i).length()/256); ! cv[2]=(char)(v.get(i).length()%256); ! out+=String.copyValueOf(c)+String.copyValueOf(cv)+v.get(i); } return out; *************** *** 787,802 **** */ protected boolean parseSNMPHeader(String in) { ! m_len=in.charAt(0)*256+in.charAt(1); ! m_majorver=in.charAt(2); ! m_minorver=in.charAt(3); ! m_release=in.charAt(4); ! m_id=in.charAt(5)*256+in.charAt(6); ! m_type=in.charAt(7); ! m_last=in.substring(8); ! if(m_len!=in.length()-2) { ! m_errorstatus = SNMP_ERROR_wrongLength; ! return false; } ! return true; } --- 906,924 ---- */ protected boolean parseSNMPHeader(String in) { ! if(in.length()>=8) { ! m_len=in.charAt(0)*256+in.charAt(1); ! m_majorver=in.charAt(2); ! m_minorver=in.charAt(3); ! m_release=in.charAt(4); ! m_id=in.charAt(5)*256+in.charAt(6); ! m_type=in.charAt(7); ! m_last=in.substring(8); ! if(m_len!=in.length()-2) { ! m_errorstatus = SNMP_ERROR_wrongLength; ! return false; ! } ! return true; } ! return false; } *************** *** 810,822 **** */ protected boolean parseSNMPPassword(String in) { ! int l; ! l=in.charAt(0)*256+in.charAt(1); ! if(l+2>=in.length()) { ! m_errorstatus = SNMP_ERROR_wrongLength; ! return false; } ! m_password=in.substring(2, l+2); ! m_last=in.substring(l+2); ! return true; } --- 932,946 ---- */ protected boolean parseSNMPPassword(String in) { ! if(in.length()>=2) { ! int l=in.charAt(0)*256+in.charAt(1); ! if(in.length()<l+2) { ! m_errorstatus = SNMP_ERROR_wrongLength; ! return false; ! } ! m_password=in.substring(2, l+2); ! m_last=in.substring(l+2); ! return true; } ! return false; } *************** *** 840,844 **** else { m_errorstatus=SNMP_ERROR_noSuchName; ! m_errorindex=m_vars.size(); return false; } --- 964,968 ---- else { m_errorstatus=SNMP_ERROR_noSuchName; ! m_errorindex=m_vars.size()+1; return false; } *************** *** 849,852 **** --- 973,977 ---- } } + if(c.length!=i) return false; return true; } *************** *** 863,867 **** char[] c = in.toCharArray(); int i,len; - int curi=0; m_vars.clear(); --- 988,991 ---- *************** *** 877,885 **** m_values.add(String.copyValueOf(c, i+7, len)); i+=len; - curi++; } else { m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex=curi; return false; } --- 1001,1008 ---- m_values.add(String.copyValueOf(c, i+7, len)); i+=len; } else { m_errorstatus = SNMP_ERROR_noSuchName; ! m_errorindex=m_vars.size()+1; return false; } *************** *** 905,908 **** --- 1028,1032 ---- } } + if(c.length!=i) return false; return true; } *************** *** 917,921 **** */ protected boolean parseSNMPError(String in) { ! if(in.length()<=7) { m_errorstatus = SNMP_ERROR_wrongLength; return false; --- 1041,1045 ---- */ protected boolean parseSNMPError(String in) { ! if(in.length()<7) { m_errorstatus = SNMP_ERROR_wrongLength; return false; *************** *** 962,967 **** * @version v0.01 */ ! protected void updateValues() { ! } --- 1086,1183 ---- * @version v0.01 */ ! protected void updateMIBValues() { ! String str=""; ! String[] stra; ! ArrayList alist; ! Object[] oba; ! try { ! //"Counter.InputIP" ! getIDbyName("Counter","InputIP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getinputIPCount()).toString()); ! //"Counter.OutputIP" ! getIDbyName("Counter","OutputIP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getoutputIPCount()).toString()); ! //"Counter.ARP" ! getIDbyName("Counter","ARP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getARPCount()).toString()); ! //"Counter.InputTCP" ! getIDbyName("Counter","InputTCP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getTCPinputCount()).toString()); ! //"Counter.OutputTCP" ! getIDbyName("Counter","OutputTCP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getTCPoutputCount()).toString()); ! //"Counter.ReceiveDuplicatedTCP" ! getIDbyName("Counter","ReceiveDuplicatedTCP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getTCPRDCount()).toString()); ! //"Counter.SendDuplicatedTCP" ! getIDbyName("Counter","SendDuplicatedTCP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getTCPSDCount()).toString()); ! //"Counter.SendAckTCP" ! getIDbyName("Counter","SendAckTCP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getTCPACKCount()).toString()); ! //"Counter.InputUDP" ! getIDbyName("Counter","InputUDP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getUDPinputCount()).toString()); ! //"Counter.OutputUDP" ! getIDbyName("Counter","OutputUDP"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, Integer.valueOf(mParentStack.getUDPoutputCount()).toString()); ! //"Device.AllInterfaces" ! str=""; ! alist=((Node)current_device).getAllInterfacesNames(); ! for(int i=0;i<alist.size();i++) { ! if(i!=0) str+=", "; ! str+=alist.get(i).toString(); ! } ! getIDbyName("Device", "AllInterfaces"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, str); ! //"Device.AvailableInterfaces" ! str=""; ! stra=((Node)current_device).getAvailableInterfaces(); ! for(int i=0;i<stra.length;i++) { ! if(i!=0) str+=", "; ! str+=stra[i]; ! } ! getIDbyName("Device", "AvailableInterfaces"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, str); ! //"Device.Hostname" ! getIDbyName("Device", "Hostname"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, ((Node)current_device).getName()); ! //"Device.MACaddress_Eth0" ! getIDbyName("Device", "MACaddress_Eth0"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, ((Node)current_device).getMACAddress("eth0")); ! //"IP.AllInterfaces" ! str=""; ! oba=((NetworkLayerDevice)current_device).getAllInterfaces(); ! for(int i=0;i<oba.length;i++) { ! if(i!=0) str+=", "; ! str+=oba[i].toString(); ! } ! getIDbyName("IP", "AllInterfaces"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, str); ! //"IP.ARPTable" ! str=""; ! stra = ((NetworkLayerDevice)current_device).getARPTable(); ! for(int i=1;i<stra.length;i++) { ! if(i!=1) str+=", "; ! str+=stra[i]; ! } ! getIDbyName("IP", "ARPTable"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, str); ! //"IP.DefaultGateway" ! getIDbyName("IP", "DefaultGateway"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, ((NetworkLayerDevice)current_device).getDefaultGateway()); ! //"IP.IPaddress_Eth0" ! getIDbyName("IP", "Address_Eth0"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, ((NetworkLayerDevice)current_device).getIPAddress("eth0")); ! //"IP.subnetMask_Eth0" ! getIDbyName("IP", "SubnetMask_Eth0"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, ((NetworkLayerDevice)current_device).getSubnetMask("eth0")); ! //"SNMP.CommunityName" ! getIDbyName("SNMP", "CommunityName"); ! SNMPgroups.get(m_GroupID).value.set(m_InstanceID, current_password); ! } ! catch(Exception e) { ! System.out.print(e.toString()); ! } } *************** *** 971,985 **** * @version v0.01 */ ! private int checkValues(String var,String val) { ! if(var.compareTo("test.test_1")==0) { if(val.compareTo("B")==0 || val.compareTo("C")==0) return 0; else return SNMP_ERROR_wrongValue; } ! else if(var.compareTo("test.test_2")==0) { if(Integer.parseInt(val,10)>0 && Integer.parseInt(val,10)<99) return 0; else return SNMP_ERROR_wrongValue; } return SNMP_ERROR_readOnly; } /** --- 1187,1241 ---- * @version v0.01 */ ! private int checkMIBValue(String var,String val) { ! if(var.compareToIgnoreCase("test.test_1")==0) { if(val.compareTo("B")==0 || val.compareTo("C")==0) return 0; else return SNMP_ERROR_wrongValue; } ! else if(var.compareToIgnoreCase("test.test_2")==0) { if(Integer.parseInt(val,10)>0 && Integer.parseInt(val,10)<99) return 0; else return SNMP_ERROR_wrongValue; } + else if(var.compareToIgnoreCase("IP.DefaultGateway")==0) { + if(val!="" || var!=null) return 0; + } + else if(var.compareToIgnoreCase("IP.Address_Eth0")==0) { + if(val!="" || var!=null) return 0; + } + else if(var.compareToIgnoreCase("IP.SubnetMask_Eth0")==0) { + if(val!="" || var!=null) return 0; + } + else if(var.compareToIgnoreCase("SNMP.CommunityName")==0) { + if(val!="" || var!=null) return 0; + } return SNMP_ERROR_readOnly; } + + /** + * This method set MIB value + * @author QweR + * @version v0.01 + */ + private int setMIBValue(String var,String val) { + try { + int er=0; + if((er=checkMIBValue(var, val))!=0) return er; + if(var.compareToIgnoreCase("IP.DefaultGateway")==0) { + ((NetworkLayerDevice)current_device).setDefaultGateway(val); + } + else if(var.compareToIgnoreCase("IP.IPaddress_Eth0")==0) { + ((NetworkLayerDevice)current_device).setIPAddress("Eth0", val); + } + else if(var.compareToIgnoreCase("IP.subnetMask_Eth0")==0) { + ((NetworkLayerDevice)current_device).setCustomSubnetMask("Eth0", val); + } + else if(var.compareToIgnoreCase("SNMP.CommunityName")==0) { + current_password=val; + } + } + catch(Exception e) { + System.out.print(e.toString()); + } + return 0; + } /** *************** *** 993,997 **** for(i=0;i<SNMPgroups.size();i++) { ! if(SNMPgroups.get(i).name.compareTo(n)==0) break; } if(i>=SNMPgroups.size()) return (-1); --- 1249,1253 ---- for(i=0;i<SNMPgroups.size();i++) { ! if(SNMPgroups.get(i).name.compareToIgnoreCase(n)==0) break; } if(i>=SNMPgroups.size()) return (-1); *************** *** 1024,1031 **** protected String getPacketData(String pack) { ! String out=""; ! out += Integer.toString((int) pack.charAt(0), 16); ! for(int i=1;i<pack.length();i++) { ! out += ","+Integer.toString((int) pack.charAt(i), 16); } return out; --- 1280,1289 ---- protected String getPacketData(String pack) { ! String out="",ob=""; ! for(int i=0;i<pack.length();i++) { ! if(i!=0) out += " "; ! ob = Integer.toString((int) pack.charAt(i), 16).toUpperCase(); ! if(ob.length()<=1) out += "0"; ! out += ob; } return out; *************** *** 1051,1055 **** for(i=0;i<instance.size();i++) { ! if(instance.get(i).compareTo(n)==0) break; } if(i>=instance.size()) return (-1); --- 1309,1313 ---- for(i=0;i<instance.size();i++) { ! if(instance.get(i).compareToIgnoreCase(n)==0) break; } if(i>=instance.size()) return (-1); |