Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r5732 - trunk/geant2_java-sshtelnet-mp/src/test/java

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r5732 - trunk/geant2_java-sshtelnet-mp/src/test/java


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r5732 - trunk/geant2_java-sshtelnet-mp/src/test/java
  • Date: Wed, 18 Aug 2010 17:22:06 +0100

Author: psnc.pietrzak
Date: 2010-08-18 17:22:06 +0100 (Wed, 18 Aug 2010)
New Revision: 5732

Removed:
trunk/geant2_java-sshtelnet-mp/src/test/java/MockTelnetRouter.java
Log:
Refactored the package

Deleted: trunk/geant2_java-sshtelnet-mp/src/test/java/MockTelnetRouter.java
===================================================================
--- trunk/geant2_java-sshtelnet-mp/src/test/java/MockTelnetRouter.java
2010-08-18 16:21:26 UTC (rev 5731)
+++ trunk/geant2_java-sshtelnet-mp/src/test/java/MockTelnetRouter.java
2010-08-18 16:22:06 UTC (rev 5732)
@@ -1,111 +0,0 @@
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-public class MockTelnetRouter {
-
- public static void main(String[] args) {
- if (args.length < 2) {
- System.err.println("Usage: " +
MockTelnetRouter.class.getName() + " <ip address> <port> [juniper | cisco]");
- System.err.println("If not determined by the execution
argument, it is assumed that its the cisco router.");
- System.err.println();
- System.err.println("You can also override default parameter
values by setting the following properties:");
- System.err.println("usernamePrompt - prompt sent by the
router when waiting for username.");
- System.err.println("passwordPrompt - prompt sent by the
router when waiting for password.");
- System.err.println("prompt - prompt sent by the
router when waiting for command.");
- System.err.println("response - response for the command
sent by the router.");
- System.err.println("In order to set the property add
-Dname=value to the execution arguments.");
- System.exit(1);
- }
-
- final MockTelnetRouter app = new MockTelnetRouter();
- try {
- app.run(app.getAddress(args), app.getBacklog(args),
app.getPort(args), app.isJuniper(args));
- } catch (UnknownHostException ex) {
- ex.printStackTrace();
- }
- }
-
- public void run(InetAddress address, int backlog, int port, boolean
juniper) {
- try {
- final ServerSocket serverSocket = new
ServerSocket(port, backlog, address);
- System.out.println(getDeviceName(juniper) + " router
listening for telnet connections on " + serverSocket.getInetAddress());
- while (true) {
- final Socket socket = serverSocket.accept();
- System.out.println("--- Connection from " +
socket.getInetAddress() + "...");
- final OutputStream out = socket.getOutputStream();
- final InputStream in = socket.getInputStream();
-
- System.out.print(getUsernamePrompt(juniper));
- waitForResponse(getUsernamePrompt(juniper), out,
in);
- System.out.print(getPasswordPrompt(juniper));
- waitForResponse(getPasswordPrompt(juniper), out,
in);
- System.out.print(getPrompt(juniper));
- waitForResponse(getPrompt(juniper), out, in);
-
- out.write(getResponse(juniper).getBytes());
- out.write(getPrompt(juniper).getBytes());
- out.flush();
- System.out.println(getResponse(juniper));
- System.out.println(getPrompt(juniper));
- socket.close();
- System.out.println("--- Finished connection from
" + socket.getInetAddress());
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- private String getDeviceName(boolean juniper) {
- return (juniper ? "Juniper" : "Cisco");
- }
-
- private int getBacklog(String[] args) {
- return 0;
- }
- private Integer getPort(String[] args) {
- return Integer.valueOf(args[1]);
- }
- private InetAddress getAddress(String[] args)
- throws UnknownHostException {
- return InetAddress.getAllByName(args[0])[0];
- }
- private boolean isJuniper(String[] args) {
- return (args.length >= 3) &&
args[2].equalsIgnoreCase("juniper");
- }
-
- private String getProperty(String name, String defaultValue) {
- final String result = System.getProperty(name);
- if (result != null)
- return result;
- return defaultValue;
- }
- private String getPasswordPrompt(boolean juniper) {
- return getProperty("passwordPrompt", "Password:");
- }
- private String getUsernamePrompt(boolean juniper) {
- return getProperty("usernamePrompt", (juniper) ? "login:" :
"Username:");
- }
- private String getPrompt(boolean juniper) {
- return getProperty("prompt", (juniper) ? ">" : "%");
- }
- private String getResponse(boolean juniper) {
- return getProperty("response", "show ip bgp neighbor 127.0.0.1 No
further information\n");
- }
-
- private void waitForResponse(final String prompt,
- final OutputStream out, final InputStream in) throws
IOException {
- out.write(prompt.getBytes());
- out.flush();
- for (int i = in.read(); i != 10; i = in.read()) {
- if (i == 13) continue;
- System.out.print((char) i);
- }
- System.out.println();
- }
-}
\ No newline at end of file



  • [pS-dev] [GEANT/SA2/ps-java-services] r5732 - trunk/geant2_java-sshtelnet-mp/src/test/java, svn-noreply, 08/18/2010

Archive powered by MHonArc 2.6.16.

Top of Page