/* $Id: //depot/tools/main/performance/perfstat_cluster/src/connectionHandler.hpp#44 $ */ #ifndef CONNECTIONHANDLER_H #define CONNECTIONHANDLER_H #include #include #include #include #include #include #include #ifndef WIN32 #include #ifndef __APPLE__ #include #endif #endif #include #include #include using namespace std; typedef enum { PERFSTAT_SSH_ERRORS_SESSION_ALREADY_EXISTS = 0, PERFSTAT_SSH_ERRORS_WRONG_PASSWORD, PERFSTAT_SSH_ERRORS_OTHERS }PERFSTAT_SSH_ERRORS; /** class for for handling SSH connection from filers */ class connectionHandler { string hostName; outputHandler * commonOutputHandle; CLIHandler *cliHandle; string filerMode; string nodePrompt; string switchPrompt; string systemShellPrompt; int requestTimeoutSecs; bool iterationChanged; int bfailCode; /* Authentication fail Response code = 401 * Connect failed = 0 */ PERFSTAT_SSH_ERRORS sshError; // SSH Connectivity Error code CkSsh ssh; CkSshKey* SSHKey; long channelNum; long channelSystemShell; #ifndef WIN32 LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; LIBSSH2_KNOWNHOSTS *nh; int clientSocket; int waitOnSocket(int, LIBSSH2_SESSION *); #endif void setSystemShellPrompt(bool sysShellFlagRR=false); //added the new flag to work around the RR.1 systemshell clean exit bool setFilerPrompt(); bool setSwitchPrompt(); bool SetRemoteHostPrompt(); void sleepBtwRead(int); bool modifiedConnect(); public: //664426 Perfstat disconnect ssh for high value of option t bool setNodePromptcounter; bool checkConnection(bool, long tchannel = -1, string username="", string password="", string h = ""); //Added username and password input for switches /** empty constructor */ connectionHandler() {}; /** constructor * takes username, password, hostname and port as args */ connectionHandler(CkSshKey*, string, int, outputHandler*, string nprompt = ""); //664426 Perfstat disconnect ssh for high value of option t connectionHandler(CkSshKey*, string, int, outputHandler*, CLIHandler*, string nprompt = "", bool setNodePromptcounter_value = false); connectionHandler(string, int, outputHandler*); connectionHandler(string, int, outputHandler*, CLIHandler*); /** provides session for the current connection * return session */ vector generateSSHKey(string, string, string); bool connectToFiler(string passwd=""); bool connectToSwitch(string, string ); #ifndef WIN32 bool connectToServer(string,string); bool sendCommandToServer(string, string, string, bool bcisco = true); bool disconnectFromServer(); bool readResponseFromServer(outputHandler*); #endif /** disconnects to the controller */ string sendCancelCommandToFiler(); void disconnectToFiler(); bool logoutSystemShell(); //added for 7-mode systemShell /** send command to execute on controller */ bool sendCommandToFiler(string); bool sendCommandToSwitch(string, string username="", string password=""); //We need username and password incase of reconnectivity /** read response from the controller */ string readResponseBufferWithPoll(outputHandler*, string hardware=""); //Added for switch string readResponseFromFiler(int timeout=0); string readResponseFromFilerWithTimeout(outputHandler*, ofstream*, int, int); bool readSystemShellResponseWithPoll(outputHandler *, ofstream* tempFilePtr = 0, bool binaryFile=false); bool readResponseFromFilerWithPoll(outputHandler*, ofstream* tempFilePtr = 0, string hardware="", bool binary=false); //Added for switch bool loginSystemShell(string,bool sysShellFlagRR=false); //added the new flag to work around the RR.1 systemshell clean exit bool connectToSystemShell(); bool sendSystemShellCommand(string, string passwd = ""); /********** HOST **************/ bool ConnectToRemoteHost(string strUserName, string strPassWord); bool ConnectToRemoteHost(string passWord); //We need username and password incase of reconnectivity bool SendCommandToRemoteHost(string strCommand); bool SendCommandToRemoteHost(string command, string strUserName, string strPassword); bool CheckForSSHConnection(string strUser, string strPasswd); bool CopyFromOneHostToOtherUsingSFTP(string strHostIP, string strUserName, string strPassWord, string strFile, string strWriteFile); bool RemoveFilesFromHost(string strHostIP, string strUserName, string strPassWord, string strFile); string readSystemShellResponse(outputHandler*); string getNodePrompt(); bool checkSignal(); bool setupSSHKeysForSystemShell(string, string, string); bool readResponseWithPoll(long, string, outputHandler*, bool, string hardware="", ofstream* tempFilePtr=0, bool binaryfile=false); //Added for switch void setSSHKey(CkSshKey*); vector createAuthenticationKey(CkSshKey*, string, string, string); void logErrorMsg(string); // string sendSystemShellCommand(string , string ); void setIterationChanged(bool); bool setupSSHKeyOnFilerAsSftp(string , string , string ); bool cleanupSSHKeyOnFilerAsSftp(string , CkSshKey* ); bool getFilesFromFilersAsSftp(string , CkSshKey*, string ); //map nodePromptMap; //string getNodePromptFromMap( string ); //string getSystemShellPassword(); PERFSTAT_SSH_ERRORS getSSHErrorCode() const; bool checkMessageLogDiverted(); string getSystemShellPrompt(); int getConnectResponseCode(); }; #endif