[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip SNMP.java,1.11,1.12 Telnet_client.java,1.5,1.6
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-02-25 22:48:41
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19142/core/protocolsuite/tcp_ip Modified Files: SNMP.java Telnet_client.java Telnet_server.java Log Message: Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Telnet_client.java 25 Feb 2006 00:00:03 -0000 1.5 --- Telnet_client.java 25 Feb 2006 22:48:34 -0000 1.6 *************** *** 79,88 **** sdPort = port; ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Telnet Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); ! Simulation.addLayerInfo(protInfo2); do --- 79,83 ---- sdPort = port; ! printInfo("Client: connecting to host " + Host + ":"+ port +". Please wait..."); do *************** *** 113,118 **** */ ! public void DisconnectEvent(){ ! System.out.print("\n---------------------------\n\nIT WORKS!!!\n\n----------------------------------\n"); } --- 108,124 ---- */ ! public void DisconnectEvent(){ ! try{ ! Disconnect(); ! } ! catch(TransportLayerException e) { ! printInfo("Client: can not disconnected: transport problem"); ! } ! catch(LowLinkException e) { ! printInfo("Client: can not disconnected: low link problem"); ! } ! printInfo("\nClient: receive disconnect event\n"); ! terminal.recvData("\nServer closed connection.\n"); ! terminal.recvData("\nQUIT"); } *************** *** 130,144 **** } - LayerInfo protInfo3 = new LayerInfo(getClass().getName()); - protInfo3.setObjectName(mParentStack.getParentNodeName()); - protInfo3.setDataType("Telnet Protocol Data"); - protInfo3.setLayer("Application "); if(appType==0){ ! protInfo3.setDescription("Application closing connection."); }else{ ! protInfo3.setDescription("Application closing connection. Now listening on " + listenPort + "."); ! } ! Simulation.addLayerInfo(protInfo3); ! mParentStack.CloseTCP(this); //mParentStack.freeTCPPort(this); --- 136,144 ---- } if(appType==0){ ! printInfo("Client: closing connection."); }else{ ! printInfo("Client: closing connection. Now listening on " + listenPort + "."); ! } mParentStack.CloseTCP(this); //mParentStack.freeTCPPort(this); *************** *** 175,184 **** //client processing recieve // printing some ... ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo); /* LayerInfo protInfo = new LayerInfo(getClass().getName()); --- 175,179 ---- //client processing recieve // printing some ... ! printInfo("Recieving echo message '" + Data + "' from server."); /* LayerInfo protInfo = new LayerInfo(getClass().getName()); *************** *** 191,210 **** if(Data.compareTo("\nQUIT")==0) { Disconnect(); } ! terminal.recvData(Data); ! ! //if(this.counts==0){ ! //Disconnect(); ! //}else{ ! // this.counts--; ! // try { ! // SendData(Data); ! //}catch(Exception e){ ! ///*TODO*: here to catch ! //} ! //} ! ! ! } } --- 186,192 ---- if(Data.compareTo("\nQUIT")==0) { Disconnect(); + terminal.recvData("\nClient: closing connection\n"); } ! terminal.recvData(Data); } } *************** *** 241,251 **** } else { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); ! terminal.recvData("Error: cannot connect to " + Host + ":" + port + "!"); this.counts=0; } --- 223,228 ---- } else { ! printInfo("Client: error: can not connect to " + Host + ":" + port + "!"); ! terminal.recvData("Client: error: cannot connect to " + Host + ":" + port + "!"); this.counts=0; } *************** *** 274,277 **** --- 251,262 ---- } + private void printInfo(String s) { + LayerInfo protInfo2 = new LayerInfo(getClass().getName()); + protInfo2.setObjectName(mParentStack.getParentNodeName()); + protInfo2.setDataType("Telnet Protocol Data"); + protInfo2.setLayer("Application "); + protInfo2.setDescription(s); + Simulation.addLayerInfo(protInfo2); + } } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Telnet_server.java 25 Feb 2006 00:00:03 -0000 1.5 --- Telnet_server.java 25 Feb 2006 22:48:34 -0000 1.6 *************** *** 37,41 **** private boolean islogin=false; private boolean ispass=false; ! private boolean isprompt=true; private boolean isnewpass=false; private String password = "123"; --- 37,41 ---- private boolean islogin=false; private boolean ispass=false; ! // private boolean isprompt=true; private boolean isnewpass=false; private String password = "123"; *************** *** 63,66 **** --- 63,67 ---- } + isenter = true; } *************** *** 75,78 **** --- 76,80 ---- { mParentStack.FreeTCPApplication(this); + isenter = true; } *************** *** 98,115 **** public void DisconnectEvent(){ ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); try{ Close(); ! printInfo("Server closing connection"); try{ Listen(); ! printInfo("Server listening on port " + listenPort); } catch(TransportLayerException e){ ! printInfo("Server can not listen on port " + listenPort); } } catch(TransportLayerException e){ ! printInfo("Server can not close connection"); } } --- 100,117 ---- public void DisconnectEvent(){ ! printInfo("Server: client closed connection"); try{ Close(); ! printInfo("Server: closing connection"); try{ Listen(); ! printInfo("Server: listening on port " + listenPort); } catch(TransportLayerException e){ ! printInfo("Server: can not listen on port " + listenPort); } } catch(TransportLayerException e){ ! printInfo("Server: can not close connection"); } } *************** *** 129,135 **** if(appType==0){ ! printInfo("Application closing connection."); }else{ ! printInfo("Application closing connection. Now listening on port" + listenPort + "."); } --- 131,137 ---- if(appType==0){ ! printInfo("Server: closing connection."); }else{ ! printInfo("Server: closing connection. Now listening on port" + listenPort + "."); } *************** *** 167,172 **** //server processing recieve ! printInfo("Recieving echo message '" + Data + "' from client."); String outData=""; if(isenter && Data.compareTo("\n")==0) { --- 169,175 ---- //server processing recieve ! printInfo("Server: recieving echo message '" + Data + "' from client."); + while(Data.length()>0) { String outData=""; if(isenter && Data.compareTo("\n")==0) { *************** *** 254,262 **** } try { ! printInfo("Sending echo message '" + outData + "' to client."); SendData(outData); if(outData.compareTo("\nQUIT")==0) { Close(); Listen(); isenter = true; } --- 257,267 ---- } try { ! printInfo("Server: sending message '" + outData + "' to client."); SendData(outData); if(outData.compareTo("\nQUIT")==0) { Close(); Listen(); + printInfo("Server: closing connection"); + printInfo("Server: listening on port " + listenPort); isenter = true; } *************** *** 265,268 **** --- 270,275 ---- ///*TODO*: here to catch } + Data = Data.substring(1); + } } *************** *** 296,306 **** } else if(cmd.compareTo("?")==0) { ! out += "route \t\t show/edit route table\n"; ! out += "arp \t\t show/edit arp table"; ! out += "snmp \t\t on/off snmp agent\n"; ! out += "counters \t\t show network counters\n"; ! out += "passwd \t\t change password\n"; ! out += "quit \t\t close terminal session\n"; ! out += "? \t\t show this screen\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { --- 303,313 ---- } else if(cmd.compareTo("?")==0) { ! out += " route \t show/edit route table\n"; ! out += " arp \t show/edit arp table\n"; ! out += " snmp \t on/off snmp agent\n"; ! out += " counters\t show network counters\n"; ! out += " passwd \t change password\n"; ! out += " quit \t close terminal session\n"; ! out += " ? \t show this screen\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { *************** *** 310,316 **** String tokens[]=cmd.split(" "); Matcher m; - // if(m.find()) { - // if(m.group(1).compareTo("route")==0); - // } if(tokens[0].compareTo("route")==0){ if((m=Pattern.compile(" +print$").matcher(cmd)).find()) { --- 317,320 ---- *************** *** 324,331 **** } else if((m=Pattern.compile(" +add +([^ ]+) +([^ ]+) +([^ ]+)( +([^ ]+|\\*))?$").matcher(cmd)).find()) { ! String a = m.group(5); ! String b = m.group(4); ! Route_entry r = new Route_entry(m.group(1), m.group(5), m.group(3), m.group(2), 0); ! mParentStack.addRoute(r); out+="Route added.\n"; } --- 328,337 ---- } else if((m=Pattern.compile(" +add +([^ ]+) +([^ ]+) +([^ ]+)( +([^ ]+|\\*))?$").matcher(cmd)).find()) { ! if(m.group(5)!=null) { ! mParentStack.addRoute(new Route_entry(m.group(1), m.group(5), m.group(3), m.group(2), 0)); ! } ! else { ! mParentStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); ! } out+="Route added.\n"; } *************** *** 336,342 **** else{ out+="Unknown route command. Usage:\n"; ! out+="route add (host_ip|network_ip) target_interface netmask (gateway|*) \n"; ! out+="route del (host_ip|network_ip) \n"; ! out+="route print \n"; } } --- 342,349 ---- else{ out+="Unknown route command. Usage:\n"; ! out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\n" + ! " add new route record\n"; ! out+=" route del (<host ip>|<network ip>) delete route record\n"; ! out+=" route print print route table\n"; } } *************** *** 346,350 **** String l_pass="public"; if(m.group(1).compareTo("on")!=0) l_port = Integer.parseInt(m.group(1)); ! if(m.group(2).compareTo("")!=0) l_pass = m.group(2); SNMP snmpa = (SNMP) mDevice.getApp(161); snmpa.setPassword(l_pass); --- 353,359 ---- String l_pass="public"; if(m.group(1).compareTo("on")!=0) l_port = Integer.parseInt(m.group(1)); ! if(m.group(3)!=null) { ! if(m.group(3).compareTo("")!=0) l_pass = m.group(3); ! } SNMP snmpa = (SNMP) mDevice.getApp(161); snmpa.setPassword(l_pass); *************** *** 352,355 **** --- 361,365 ---- try{ snmpa.Listen(); + out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\n"; } catch(TransportLayerException e) { *************** *** 361,364 **** --- 371,375 ---- try{ snmpa.Close(); + out+="SNMP agent stoped\n"; } catch(TransportLayerException e) { *************** *** 366,369 **** --- 377,385 ---- } } + else { + out+="Unknown snmp command. Usage:\n"; + out+=" snmp (on|<port number>) [community name] Start SNMP agent\n"; + out+=" snmp off Stop SNMP agent\n"; + } } else if(tokens[0].compareTo("passwd")==0){ *************** *** 387,391 **** } else if(tokens[0].compareTo("arp")==0){ ! } else out = tokens[0] + ": command not found\n"; --- 403,433 ---- } else if(tokens[0].compareTo("arp")==0){ ! if((m=Pattern.compile(" +-a$").matcher(cmd)).find()) { ! try{ ! String ArpTable[] = mParentStack.getARPTable(); ! for(int i=0;i<ArpTable.length;i++) ! { ! out += ArpTable[i] + "\n"; ! } ! } ! catch(Exception e) ! { ! //Should never get here. ! } ! } ! else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { ! mParentStack.removeARP(m.group(1)); ! out += "Removed ARP entry for ip " + m.group(1) + "\n"; ! } ! else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { ! mParentStack.addToARPStatic(m.group(1), m.group(2)); ! out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\n"; ! } ! else { ! out+="Unknown arp command. Usage:\n"; ! out+=" arp -a print ARP table\n"; ! out+=" arp -d <ip address> delete record from ARP table\n"; ! out+=" arp -s <ip address> <MAC address> add new ARP record\n"; ! } } else out = tokens[0] + ": command not found\n"; Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SNMP.java 24 Feb 2006 10:20:11 -0000 1.11 --- SNMP.java 25 Feb 2006 22:48:33 -0000 1.12 *************** *** 1232,1240 **** ((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) { --- 1232,1241 ---- ((NetworkLayerDevice)current_device).setDefaultGateway(val); } ! else if(var.compareToIgnoreCase("IP.Address_Eth0")==0) { ! String a = ((NetworkLayerDevice)current_device).setIPAddress("eth0", val); ! printInfo(">>>>>>>>>> " + a); } else if(var.compareToIgnoreCase("IP.subnetMask_Eth0")==0) { ! ((NetworkLayerDevice)current_device).setCustomSubnetMask("eth0", val); } else if(var.compareToIgnoreCase("SNMP.CommunityName")==0) { *************** *** 1244,1247 **** --- 1245,1249 ---- catch(Exception e) { //System.out.print(e.toString()); + printInfo("bad value: " + var + " = \"" + val); return SNMP_ERROR_badValue; } |