fiberhome: add prelimunary add ONU support
Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
600555596d
commit
ee22ecf693
4 files changed
+724
No files matched your search
@@ -13,6 +13,9 @@ class FiberhomeManager {
|
||||
username: '1',
|
||||
password: '1',
|
||||
timeout: 15000
|
||||
},
|
||||
olt: {
|
||||
name: '131.0.192.9' // OLT configurada no TL1
|
||||
}
|
||||
};
|
||||
|
||||
@@ -377,6 +380,177 @@ class FiberhomeManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Descobrir porta PON onde a ONU está descoberta
|
||||
* @param {string} serial - Serial da ONU (MAC address)
|
||||
*/
|
||||
async descobrirPortaPON(serial) {
|
||||
try {
|
||||
this.logger.debug('Descobrindo porta PON para ONU', { serial });
|
||||
|
||||
// Conectar ao UNM2000
|
||||
const conectado = await this.conectarUNM2000();
|
||||
if (!conectado) {
|
||||
throw new Error('Não foi possível conectar ao UNM2000');
|
||||
}
|
||||
|
||||
// Buscar em todas as portas PON possíveis (slots 1-20, portas 1-16)
|
||||
for (let slot = 1; slot <= 20; slot++) {
|
||||
for (let porta = 1; porta <= 16; porta++) {
|
||||
const ponId = `NA-NA-${slot}-${porta}`;
|
||||
const comando = `LST-UNREGONU::OLTID=${this.config.olt.name},PONID=${ponId}:${this.commandId++}::;`;
|
||||
|
||||
this.logger.debug('Consultando porta PON', { ponId });
|
||||
const resultado = await this.executarComandoTL1(comando);
|
||||
|
||||
if (resultado.success && resultado.data) {
|
||||
// Verificar se a ONU está na resposta
|
||||
if (resultado.data.toUpperCase().includes(serial.toUpperCase())) {
|
||||
this.logger.info('Porta PON descoberta', { serial, ponId });
|
||||
return {
|
||||
success: true,
|
||||
portAlias: `${slot}-${porta}`,
|
||||
slot,
|
||||
porta
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Pequeno delay entre consultas para não sobrecarregar
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
}
|
||||
}
|
||||
|
||||
// ONU não encontrada
|
||||
this.logger.warn('ONU não encontrada em nenhuma porta PON', { serial });
|
||||
return {
|
||||
success: false,
|
||||
error: 'ONU não encontrada em nenhuma porta PON. Verifique se a ONU está ligada e descoberta pela OLT.'
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao descobrir porta PON', { serial, error: error.message });
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adicionar ONU Fiberhome via TL1
|
||||
* @param {string} serial - Serial da ONU (MAC address)
|
||||
* @param {string} usuario - Nome/alias do usuário
|
||||
* @param {number} vlan - VLAN ID (padrão: 1002)
|
||||
* @param {string} onuType - Tipo da ONU (AN5506-02-B ou AN5506-01-A)
|
||||
*/
|
||||
async adicionarOnuFiberhome(serial, usuario, vlan = 1002, onuType = 'AN5506-02-B') {
|
||||
try {
|
||||
this.logger.info('Iniciando adição de ONU Fiberhome via TL1', {
|
||||
serial, usuario, vlan, onuType
|
||||
});
|
||||
|
||||
// Conectar ao UNM2000
|
||||
const conectado = await this.conectarUNM2000();
|
||||
if (!conectado) {
|
||||
throw new Error('Não foi possível conectar ao UNM2000');
|
||||
}
|
||||
|
||||
// Descobrir porta PON automaticamente
|
||||
const descoberta = await this.descobrirPortaPON(serial);
|
||||
if (!descoberta.success) {
|
||||
throw new Error(descoberta.error);
|
||||
}
|
||||
|
||||
const portAlias = descoberta.portAlias;
|
||||
const nameOlt = this.config.olt.name;
|
||||
|
||||
this.logger.info('Porta PON descoberta', { portAlias, nameOlt });
|
||||
|
||||
// 1. ADD-ONU: Autenticar a ONU
|
||||
const addOnuCmd = `ADD-ONU::OLTID=${nameOlt},PONID=NA-NA-${portAlias}:${this.commandId++}::AUTHTYPE=MAC,ONUTYPE=${onuType},NAME=${usuario},ONUID=${serial};`;
|
||||
this.logger.debug('Executando ADD-ONU', { comando: addOnuCmd });
|
||||
|
||||
const resultadoAdd = await this.executarComandoTL1(addOnuCmd);
|
||||
if (!resultadoAdd.success) {
|
||||
throw new Error(`Falha ao adicionar ONU: ${resultadoAdd.error}`);
|
||||
}
|
||||
|
||||
// Aguardar um pouco para a ONU ser registrada
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
// 2. SET-WANSERVICE: Configurar WAN services
|
||||
// Determina quantas portas configurar baseado no tipo da ONU
|
||||
const numPortas = onuType === 'AN5506-02-B' ? 2 : 1;
|
||||
|
||||
for (let porta = 1; porta <= numPortas; porta++) {
|
||||
const setWanCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::STATUS=1,MODE=2,CONNTYPE=1,VLAN=${vlan},COS=0,QOS=2,UPORT=${porta};`;
|
||||
this.logger.debug(`Configurando WAN Service porta ${porta}`, { comando: setWanCmd });
|
||||
|
||||
const resultadoWan = await this.executarComandoTL1(setWanCmd);
|
||||
if (!resultadoWan.success) {
|
||||
this.logger.warn(`Aviso ao configurar WAN porta ${porta}: ${resultadoWan.error}`);
|
||||
// Não lança erro, apenas registra o aviso
|
||||
}
|
||||
|
||||
// Pequeno delay entre comandos
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
// 3. CFG-WEBADMINISTRATOR: Configurar autenticação web
|
||||
const cfgWebCmd = `CFG-WEBADMINISTRATOR::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::WEBUSERNAME=admin,WEBPASSWORD=clicknet10;`;
|
||||
this.logger.debug('Configurando autenticação web', { comando: cfgWebCmd });
|
||||
|
||||
const resultadoWeb = await this.executarComandoTL1(cfgWebCmd);
|
||||
if (!resultadoWeb.success) {
|
||||
this.logger.warn(`Aviso ao configurar autenticação web: ${resultadoWeb.error}`);
|
||||
// Não lança erro, apenas registra o aviso
|
||||
}
|
||||
|
||||
// Aguardar antes de reiniciar
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
// 4. RESET-ONU: Reiniciar a ONU
|
||||
const resetCmd = `RESET-ONU::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::;`;
|
||||
this.logger.debug('Reiniciando ONU', { comando: resetCmd });
|
||||
|
||||
const resultadoReset = await this.executarComandoTL1(resetCmd);
|
||||
if (!resultadoReset.success) {
|
||||
this.logger.warn(`Aviso ao reiniciar ONU: ${resultadoReset.error}`);
|
||||
// Não lança erro, apenas registra o aviso
|
||||
}
|
||||
|
||||
this.logger.info('ONU Fiberhome adicionada com sucesso', {
|
||||
nameOlt, portAlias, serial, usuario, vlan
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'ONU adicionada com sucesso',
|
||||
details: {
|
||||
olt: nameOlt,
|
||||
porta: portAlias,
|
||||
slot: descoberta.slot,
|
||||
ponPort: descoberta.porta,
|
||||
serial: serial,
|
||||
usuario: usuario,
|
||||
vlan: vlan,
|
||||
tipo: onuType,
|
||||
portas: numPortas
|
||||
}
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao adicionar ONU Fiberhome', {
|
||||
serial, error: error.message
|
||||
});
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Desconectar TL1
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user