BiTel

Форум BiTel
bgbilling.ru     docs.bitel.ru     wiki.bitel.ru     dbinfo.bitel.ru     bgcrm.ru     billing.bitel.ru     bitel.ru    
Текущее время: 04 май 2024, 07:37

Часовой пояс: UTC + 5 часов [ Летнее время ]




Начать новую тему Ответить на тему  [ Сообщений: 3 ] 
Автор Сообщение
 Заголовок сообщения: Долго выполняется скрипт по telnet
СообщениеДобавлено: 12 апр 2012, 16:24 
Не в сети

Зарегистрирован: 15 фев 2012, 20:24
Сообщения: 88
Карма: 0
Подскажите в чем дело, скрипт работает, команды на свитчах выполняются но почему то слишком долго. Это по телнет всегда так? Версия системы 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 секунды.


Вернуться к началу
 Профиль  
 
СообщениеДобавлено: 13 апр 2012, 17:27 
Не в сети
Разработчик

Зарегистрирован: 08 ноя 2007, 01:05
Сообщения: 8343
Откуда: Уфа
Карма: 238
Я сталкивался с задержками при работе по ssh, telnet обычно быстрее. А если из консоли подцепляться telnet-клиентом то ответ дольше ? попробуйте выводить временные метки в логи в коде скрипта до соединения, после соединения, перед командой и после команды . Т.е определите на чем больше всего тормозит .


Вернуться к началу
 Профиль  
 
СообщениеДобавлено: 28 июн 2012, 10:24 
Не в сети
Клиент

Зарегистрирован: 12 фев 2008, 18:10
Сообщения: 3951
Карма: 249
Какой D-Link? Если DES-3526, то он дооолгооо сохраняет конфиг, да и вообще, порой, задумчивый он.


Вернуться к началу
 Профиль  
 
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 3 ] 

Часовой пояс: UTC + 5 часов [ Летнее время ]


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
POWERED_BY
Русская поддержка phpBB
[ Time : 0.050s | 24 Queries | GZIP : On ]