forum.bitel.ru
http://forum.bitel.ru/

Как распарсить данные Opt.82
http://forum.bitel.ru/viewtopic.php?f=44&t=12835
Страница 1 из 1

Автор:  dex [ 20 мар 2018, 09:01 ]
Заголовок сообщения:  Как распарсить данные Opt.82

Здравствуйте. Подскажите как распарсить данные Opt.82 поступающие на сервер в строковом формате?
DHCP option 82 Huawei OLT MA5603T (GPON)
Не получается распарсить ответ релея Huawei MA5603T, он выдает строковое значение VLAN и PON-порт (Circuit-ID).

Это TCP dump сервера:
IP (tos 0x0, ttl 255, id 36385, offset 0, flags [none], proto UDP (17), length 369)
x.x.x.3.67 > x.x.x.30.67: BOOTP/DHCP, Request from d4:ca:6d:58:c7:de, length 341, hops 1, xid 0x55455574, secs 2, Flags [Broadcast]
Gateway-IP x.x.x.3
Client-Ethernet-Address d4:ca:6d:58:c7:de
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Discover
Parameter-Request Option 55, length 7:
Subnet-Mask, Classless-Static-Route, Default-Gateway, Static-Route
Domain-Name-Server, NTP, Option 138
Hostname Option 12, length 8: "MikroTik"
Client-ID Option 61, length 7: ether d4:ca:6d:58:c7:de
Agent-Information Option 82, length 39:
Circuit-ID SubOption 1, length 23: 48575443AE25BD84/14/701
Remote-ID SubOption 2, length 12: 643E8CAC8882

В логах биллинга:
03-20/11:50:43 INFO [dhcpLstnr-p-10-t-8] AbstractInetDhcpProcessor2 - REQUEST:
Message type: BOOT_REQUEST
Dhcp message type: DHCP Discover{1}
htype: 1, hlen: 6, hops: 1
xid: 1430607220, secs: 7, flags: 11111111111111111000000000000000
Client IP: 0.0.0.0
Your IP: 0.0.0.0
Server IP: 0.0.0.0
Relay IP: x.x.x.3
Client MAC: {D4CA6D58C7DE}
Param request list{55}={1, 121, 3, 33, 6, 42, -118}
Host name{12}={MikroTik}
Client-ident.{61}={01D4CA6D58C7DE}
Agent information{82}=
sub{1}={343835373534343341453235424438342F31342F373031}
sub{2}={363433453843414338383832}

03-20/11:50:43 DEBUG [dhcpLstnr-p-10-t-8] AbstractInetDhcpProcessor2 - OP_BOOT_REQUEST
03-20/11:50:43 DEBUG [dhcpLstnr-p-10-t-8] AbstractInetDhcpProcessor2 - Found device by giaddr id=13
03-20/11:50:43 DEBUG [dhcpLstnr-p-10-t-8] AbstractInetDhcpProcessor2 - Found subDevice by identifier id=29
03-20/11:50:43 DEBUG [dhcpLstnr-p-10-t-8] InetDhcpProcessor2 - DHCP_DISCOVER
03-20/11:50:43 DEBUG [dhcpLstnr-p-10-t-8] InetDhcpProcessor2 - request.giaddr= x.x.x.3, clientAddress=/x.x.x.3:67
03-20/11:50:43 INFO [dhcpLstnr-p-10-t-8] InetDhcpDevice - Search serv on deviceId: 29; 2; vlanId: 0
03-20/11:50:43 INFO [dhcpLstnr-p-10-t-8] InetDhcpProcessor2 - InetServ not found.

Автор:  Phricker [ 20 мар 2018, 12:05 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Код:
# Параметры для извлечения из пакета agentRemoteId
# вид значения в опции agentRemoteId: 0 (по умолчанию) - байты, 1 - строка
#dhcp.option82.agentRemoteId.type=0

Автор:  dex [ 20 мар 2018, 12:33 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

С Remote-ID SubOption 2 - извлекается и устройство находится.
Нужно распарсить Circuit-ID SubOption 1
Circuit-ID SubOption 1, length 23: 48575443AE25BD84/14/701
Серийник/порт/vlan.

Автор:  Amir [ 21 мар 2018, 16:43 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Код:
    private static final Pattern splitPattern = Pattern.compile( "\\s*[/\\s]\\s*" );

   @Override
   public void preprocessDhcpRequest( DhcpPacket request, DhcpPacket response )
      throws Exception
   {
        DhcpOption circuitIdOption = request.getSubOption( (byte)1 );
        DhcpOption remoteIdOption = request.getSubOption( (byte)2 );

        if( circuitIdOption == null || remoteIdOption == null )
        {
            logger.info( "Options circuitId or remoteId not found" );
            return;
        }

        String remoteIdString = new String( remoteIdOption.value, "UTF8" );
        String circuitIdString = new String( circuitIdOption.value, "UTF8" );

        logger.info( "circuitId: " + circuitIdString );

        String[] circuitIdArray = splitPattern.split( circuitIdString );

Автор:  dex [ 22 мар 2018, 07:55 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Спасибо. Не могу скомпилировать скрипт, выдает ошибки.

Код:
import java.util.Arrays;
 
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpPacket;
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpProtocolHandler;
import ru.bitel.bgbilling.modules.inet.access.sa.ProtocolHandlerAdapter;
import ru.bitel.bgbilling.modules.inet.dhcp.InetDhcpProcessor;
 
public class Dhcp82ProtocolHandler
    extends ProtocolHandlerAdapter
    implements DhcpProtocolHandler


  private static final Pattern splitPattern = Pattern.compile( "\\s*[/\\s]\\s*" );

   @Override
   public void preprocessDhcpRequest( DhcpPacket request, DhcpPacket response )
      throws Exception
   {
        DhcpOption circuitIdOption = request.getSubOption( (byte)1 );
        DhcpOption remoteIdOption = request.getSubOption( (byte)2 );

        if( circuitIdOption == null || remoteIdOption == null )
        {
            logger.info( "Options circuitId or remoteId not found" );
            return;
        }

        String remoteIdString = new String( remoteIdOption.value, "UTF8" );
        String circuitIdString = new String( circuitIdOption.value, "UTF8" );

        logger.info( "circuitId: " + circuitIdString );

        String[] circuitIdArray = splitPattern.split( circuitIdString );
    }     


Вложение:
Скриншот 22-03-2018 105312.png
Скриншот 22-03-2018 105312.png [ 121.41 КБ | Просмотров: 4586 ]


Подскажите где ошибка?

Спасибо!

Автор:  borisk [ 22 мар 2018, 17:14 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Так пишет же, { не хватает.
Код:
implements DhcpProtocolHandler
{


должно быть

Автор:  dex [ 23 мар 2018, 08:11 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Все равно с ошибками. Если есть у кого рабочий скрипт, поделитесь пожалуйста. Или скажите в какой скрипт добавить этот код? И куда именно?

Автор:  borisk [ 23 мар 2018, 10:37 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Код:
import java.util.Arrays;
 
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpPacket;
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpProtocolHandler;
import ru.bitel.bgbilling.modules.inet.access.sa.ProtocolHandlerAdapter;
import ru.bitel.bgbilling.modules.inet.dhcp.InetDhcpProcessor;
 
public class Dhcp82ProtocolHandler
    extends ProtocolHandlerAdapter
    implements DhcpProtocolHandler
{

  private static final String splitPattern = "\\s*[/\\s]\\s*";

   @Override
   public void preprocessDhcpRequest( DhcpPacket request, DhcpPacket response )
      throws Exception
   {
        DhcpOption circuitIdOption = request.getSubOption( (byte)1 );
        DhcpOption remoteIdOption = request.getSubOption( (byte)2 );

        if( circuitIdOption == null || remoteIdOption == null )
        {
            logger.info( "Options circuitId or remoteId not found" );
            return;
        }

        String remoteIdString = new String( remoteIdOption.value, "UTF8" );
        String circuitIdString = new String( circuitIdOption.value, "UTF8" );

        logger.info( "circuitId: " + circuitIdString );

        String[] circuitIdArray = circuitIdString.split(splitPattern);
    }

}


Автор:  dex [ 23 мар 2018, 14:36 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Вложение:
Скриншот 23-03-2018 173055.png
Скриншот 23-03-2018 173055.png [ 136.75 КБ | Просмотров: 4545 ]

Автор:  Amir [ 23 мар 2018, 20:49 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Код:
package ...

import java.util.Arrays;

import org.apache.log4j.Logger;
 
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpOption;
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpPacket;
import ru.bitel.bgbilling.kernel.network.dhcp.DhcpProtocolHandler;
import ru.bitel.bgbilling.modules.inet.access.sa.ProtocolHandlerAdapter;
import ru.bitel.bgbilling.modules.inet.dhcp.InetDhcpProcessor;
import ru.bitel.bgbilling.modules.inet.dhcp.InetDhcpProcessor2;

public class Dhcp82ProtocolHandler
    extends ProtocolHandlerAdapter
    implements DhcpProtocolHandler
{
    private static final Logger logger = Logger.getLogger( Dhcp82ProtocolHandler.class );

    private static final String splitPattern = "\\s*[/\\s]\\s*";

    @Override
    public void preprocessDhcpRequest( DhcpPacket request, DhcpPacket response )
        throws Exception
    {
        DhcpOption circuitIdOption = request.getSubOption( (byte)1 );
        DhcpOption remoteIdOption = request.getSubOption( (byte)2 );

        if( circuitIdOption == null || remoteIdOption == null )
        {
            logger.info( "Options circuitId or remoteId not found" );
            return;
        }

        String remoteIdString = new String( remoteIdOption.value, "UTF8" );
        String circuitIdString = new String( circuitIdOption.value, "UTF8" );

        logger.info( "circuitId: " + circuitIdString );
        logger.info( "remoteIdString: " + remoteIdString );

        String[] circuitIdArray = circuitIdString.split( splitPattern );

        request.setOption( InetDhcpProcessor.AGENT_REMOTE_ID, remoteIdString );
    }

}

Автор:  dex [ 26 мар 2018, 11:44 ]
Заголовок сообщения:  Re: Как распарсить данные Opt.82

Спасибо, большое. Все заработало!

Страница 1 из 1 Часовой пояс: UTC + 5 часов [ Летнее время ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/