forum.bitel.ru http://forum.bitel.ru/ |
|
Долго выполняется скрипт по telnet http://forum.bitel.ru/viewtopic.php?f=7&t=6694 |
Страница 1 из 1 |
Автор: | ivasian [ 12 апр 2012, 16:24 ] |
Заголовок сообщения: | Долго выполняется скрипт по telnet |
Подскажите в чем дело, скрипт работает, команды на свитчах выполняются но почему то слишком долго. Это по телнет всегда так? Версия системы 5.2. Операционка win2003 код скрипта: Код: import java.util.*; import java.util.regex.*; import bitel.billing.common.iputils.*; import bitel.common.Utils.*; import bitel.billing.server.ipn.UserStatus.*; import bitel.billing.server.ipn.bean.ManadUtils.*; import bitel.billing.server.ipn.bean.VlanManager.*; import bitel.billing.server.util.telnet.*; import bitel.billing.server.util.*; import bitel.common.Preferences; import java.io.*; import java.net.*; import bitel.billing.common.module.ipn.*; import bitel.billing.server.ipn.bean.*; import bitel.billing.server.ipn.dlink.UserPortStatus; protected void doSync() { try { String host = gate.getHost(); int port = gate.getPort(); DefaultServerSetup gateSetup = new DefaultServerSetup( gate.getConfig(), "\r\n" ); String pswd = gate.getKeyword(); String login = gateSetup.getStringValue( "login"); log.info ( gate.getId() + " gate: " + host + ":" + port + " login: " + login + " pswd: " + pswd ); TelnetSession session = new TelnetSession( host, port); session.setLoginPromptSequence( ":" ); session.connect(); session.doCommand( login ); session.setLoginPromptSequence( "#" ); session.doCommand( pswd ); log.debug( "execute commands" ); doCommands(session,gateSetup); session.setLoginPromptSequence( "****" ); session.doCommand( "logout" ); log.info( "ok" ); } catch (Exception e) { throw new RuntimeException ( e ); } } private void doCommands( TelnetSession session, DefaultServerSetup gateSetup) throws IOException { String openAddress = gateSetup.getStringValue( "open.address", "255.255.255.255" ) ; log.info( "openAddress = " + openAddress ); uplinks = ru.bitel.common.Utils.toIntegerList( gateSetup.getStringValue( "uplink" ) ); List ports = getUserList( statusList ); String [] OpenRules = new String [] { "config access_profile profile_id 16 add access_id ${port} ip source_ip ${ip} port ${port} permit", "config access_profile profile_id 12 add access_id ${port} ethernet ethernet_type 0x806 port ${port} permit", "config access_profile profile_id 4 add access_id ${port} ip udp dst_port 67 port ${port} permit", "config access_profile profile_id 20 add access_id ${port} ethernet source_mac 00-00-00-00-00-00 port ${port} deny" }; String [] CloseRules = new String [] { "config access_profile profile_id 4 add access_id ${port} ip udp dst_port 67 port ${port} permit", "config access_profile profile_id 8 add access_id ${port} ip source_ip ${ip} destination_ip ${openAdress} port ${port} permit", "config access_profile profile_id 12 add access_id ${port} ethernet ethernet_type 0x806 port ${port} permit", "config access_profile profile_id 16 delete access_id ${port}" , "config access_profile profile_id 20 add access_id ${port} ethernet source_mac 00-00-00-00-00-00 port ${port} deny" }; String [] RemoveRules = new String [] { "config access_profile profile_id 4 delete access_id ${port}", "config access_profile profile_id 8 delete access_id ${port}", "config access_profile profile_id 12 delete access_id ${port}", "config access_profile profile_id 16 delete access_id ${port}", "config access_profile profile_id 20 add access_id ${port} ethernet source_mac 00-00-00-00-00-00 port ${port} deny" }; String [] BlockRules = new String [] { "config access_profile profile_id 4 add access_id ${port} ip udp dst_port 67 port ${port} permit", "config access_profile profile_id 8 add access_id ${port} ip source_ip ${ip} destination_ip ${openAdress} port ${port} permit", "config access_profile profile_id 12 add access_id ${port} ethernet ethernet_type 0x806 port ${port} permit", "config access_profile profile_id 16 delete access_id ${port}" , "config access_profile profile_id 20 add access_id ${port} ethernet source_mac 00-00-00-00-00-00 port ${port} deny" }; String [] HardLockRules = new String [] { "config access_profile profile_id 4 add access_id ${port} ip udp dst_port 67 port ${port} permit", "config access_profile profile_id 8 delete access_id ${port}", "config access_profile profile_id 12 delete access_id ${port}", "config access_profile profile_id 16 delete access_id ${port}", "config access_profile profile_id 20 add access_id ${port} ethernet source_mac 00-00-00-00-00-00 port ${port} deny" }; for( bitel.billing.server.ipn.dlink.UserPortStatus port : ports ) { switch(port.status.status) { case IPNContractStatus.STATUS_REMOVED: setRules( RemoveRules, session, port, openAddress);break; case IPNContractStatus.STATUS_OPEN: setRules( OpenRules, session, port, openAddress);break; case IPNContractStatus.STATUS_CLOSED : setRules( CloseRules, session, port, openAddress);break; case IPNContractStatus.STATUS_LOCK : setRules( BlockRules, session, port, openAddress);break; } } } private void setRules( String []rules, TelnetSession session, UserPortStatus port, String openAddress) { for(int i=0;i<rules.length;i++) { String Buf=setValues(rules[i], port.port, port.ipAddr, openAddress); log.info("rule= " + Buf); log.info("result= " + session.doCommand( Buf ) ); } } private String setValues( String rule, int port, String ip, String openAddress) { rule = rule.replaceAll( "\\$\\{port\\}", String.valueOf( port ) ); rule = rule.replaceAll( "\\$\\{ip\\}" , ip ); rule = rule.replaceAll( "\\$\\{openAdress\\}", openAddress ); return rule; } protected void doParentSync() { } public List getUserList( List statusList ) { List userList = new ArrayList(); for( bitel.billing.server.ipn.UserStatus status : statusList ) { String rule = status.rule.getRuleText(); log.info("status.rule.getRuleText=" + rule); data = rule.split( ":" ); bitel.billing.server.ipn.dlink.UserPortStatus portStatus = new bitel.billing.server.ipn.dlink.UserPortStatus(); portStatus.port = ru.bitel.common.Utils.parseInt( data[0] ); portStatus.ipAddr = data[1]; portStatus.status = status; userList.add( portStatus ); } return userList; } Скрипт выполняется правильно, но по логам он выполняется 4 секунды. |
Автор: | stark [ 13 апр 2012, 17:27 ] |
Заголовок сообщения: | Re: Долго выполняется скрипт по telnet |
Я сталкивался с задержками при работе по ssh, telnet обычно быстрее. А если из консоли подцепляться telnet-клиентом то ответ дольше ? попробуйте выводить временные метки в логи в коде скрипта до соединения, после соединения, перед командой и после команды . Т.е определите на чем больше всего тормозит . |
Автор: | snark [ 28 июн 2012, 10:24 ] |
Заголовок сообщения: | Re: Долго выполняется скрипт по telnet |
Какой D-Link? Если DES-3526, то он дооолгооо сохраняет конфиг, да и вообще, порой, задумчивый он. |
Страница 1 из 1 | Часовой пояс: UTC + 5 часов [ Летнее время ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |