[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip SNMP.java,1.2,1.3
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2005-12-04 00:48:03
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6413/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.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SNMP.java 20 Nov 2005 20:30:53 -0000 1.2 --- SNMP.java 4 Dec 2005 00:47:55 -0000 1.3 *************** *** 30,43 **** package core.protocolsuite.tcp_ip; ! import java.io.Serializable; /** ! * This is for design and future implementation of SNMP ! * @author luke_hamilton * @since Sep 17, 2004 ! * @version v0.20 */ ! public class SNMP implements Serializable{ } --- 30,170 ---- package core.protocolsuite.tcp_ip; ! import core.TransportLayerException; ! import core.InvalidNetworkLayerDeviceException; ! import core.CommunicationException; ! import core.LowLinkException; ! import core.LayerInfo; ! import core.Packet; ! import core.Simulation; ! import java.util.Vector; /** ! * @author QweR * @since Sep 17, 2004 ! * @version v0.01 */ ! 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); ! } ! /** ! * This method start to listen on application port ! * @author QweR ! * @return Nothing. ! * @version v0.01 ! */ ! public void Listen() throws TransportLayerException { ! try{ ! mParentStack.ListenUDP(this, listenPort); ! } ! catch (TransportLayerException e) { ! ! } ! } ! ! /** ! * This method stop listening on application port ! * @author QweR ! * @return Nothing. ! * @version v0.01 ! */ ! public void Close() throws TransportLayerException { ! mParentStack.CloseUDP(this); ! } ! ! /** ! * This method connects to server on the other side (imaginations from the other side.... :+) ! * @author QweR ! * @param Host - hostname or ip of server. ! * @param port - server's port ! * @version v0.01 ! */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; ! clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); ! if (clientPort>0) return true; else return false; ! } ! ! /** ! * This method disconnects from server. ! * @author QweR ! * @version v0.01 ! */ ! public void Disconnect()throws TransportLayerException { ! mParentStack.freeUDPPort(this); ! } ! ! /** ! * This method sends data to the other side. ! * @param Data to send ! * @author QweR ! * @version v0.01 ! */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.sendUDP(this, Data); ! } ! ! /** ! * This method recieves data from the other side. ! * @param Data to recv ! * @author QweR ! * @version v0.01 ! */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { ! ! } ! ! 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; ! else SNMPID++; ! return SNMPID; ! } } |