trace + backup propertie
This commit is contained in:
1 parent
b3b1edec17
commit
ea73e91aa4
8 files changed
+164
-37
No files matched your search
@@ -3,6 +3,7 @@ import { buildSoapEnvelope } from '../protocol/soap.js'
|
||||
import { CWMPMessageBuilder } from '../protocol/common/cwmp_message_builder.js'
|
||||
import { StateMachineManager } from '../services/cwmp/state_machine_manager.js'
|
||||
import { Device, detectDataModelFromParams } from '../domain/device/device.js'
|
||||
import { reclassifyDeviceFromCatalog } from '../services/parameter_writability.js'
|
||||
import { DeviceId } from '../domain/device/device_id.js'
|
||||
import { DeviceParameter, DeviceProperty } from '../domain/device/device_parameter.js'
|
||||
import DeviceModel from '../models/device.js'
|
||||
@@ -120,6 +121,12 @@ export default class CwmpController {
|
||||
if (paramValues.length > 0) {
|
||||
device.updateFromValues(paramValues)
|
||||
}
|
||||
|
||||
// Reclassify properties → parameters using catalog when GPN is unsupported
|
||||
if (device.gpnStatus === 'unsupported') {
|
||||
reclassifyDeviceFromCatalog(device)
|
||||
}
|
||||
|
||||
device.setTmpParamValues(paramValues)
|
||||
|
||||
// Detect TR data model from Inform parameter names (Device.* = TR-181, InternetGatewayDevice.* = TR-098)
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
import { Device } from '../../domain/device/device.js'
|
||||
import { DeviceParameter } from '../../domain/device/device_parameter.js'
|
||||
import { ParameterType } from '../../domain/shared/types.js'
|
||||
import { CWMPTaskQueue, ResultStatus, TaskResult } from './task_queue.js'
|
||||
import { normalizePath } from '../parameter_writability.js'
|
||||
import { reclassifyDeviceFromCatalog } from '../parameter_writability.js'
|
||||
import DeviceModel from '../../models/device.js'
|
||||
import logger from '@adonisjs/core/services/logger'
|
||||
import { createRequire } from 'node:module'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const tr181Catalog: Array<{ path: string; writable: boolean; deviceClass: string }> =
|
||||
require('../../../config/tr181-catalog.json')
|
||||
const catalogWritableIndex = new Set(
|
||||
tr181Catalog.filter((e) => e.writable).map((e) => e.path)
|
||||
)
|
||||
|
||||
// Parameter types (simplified from legacy provisioning domain)
|
||||
interface SetParameterValue {
|
||||
@@ -93,33 +84,8 @@ export class DeviceActionExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reclassify device properties as parameters using the TR-181 catalog.
|
||||
* Called when GPN is unsupported — properties that are writable per the catalog
|
||||
* should be moved to parameters so the configuration engine can write to them.
|
||||
* Get parameter values from device.
|
||||
*/
|
||||
private reclassifyFromCatalog(device: Device): void {
|
||||
const properties = device.getProperties()
|
||||
let reclassified = 0
|
||||
|
||||
for (const prop of properties) {
|
||||
const normalized = normalizePath(prop.name)
|
||||
if (catalogWritableIndex.has(normalized)) {
|
||||
// Move from properties to parameters (writable)
|
||||
const snap = prop.toSnapshot()
|
||||
device.setParameter(
|
||||
new DeviceParameter(snap.name, snap.value, snap.type, snap.createdAt, snap.updatedAt, snap.notification, snap.accessList)
|
||||
)
|
||||
// Remove from properties map
|
||||
;(device as any)._properties.delete(prop.name)
|
||||
reclassified++
|
||||
}
|
||||
}
|
||||
|
||||
if (reclassified > 0) {
|
||||
logger.debug({ identifier: device.identifier, reclassified }, '[DeviceAction] Reclassified properties → parameters via catalog')
|
||||
}
|
||||
}
|
||||
|
||||
async getParameterValues(
|
||||
device: Device,
|
||||
parameterPaths: string[],
|
||||
@@ -208,7 +174,7 @@ export class DeviceActionExecutor {
|
||||
if (code === 9000 || code === 9001) {
|
||||
device.setGpnStatus('unsupported')
|
||||
// Reclassify parameters using TR-181 catalog writability
|
||||
this.reclassifyFromCatalog(device)
|
||||
reclassifyDeviceFromCatalog(device)
|
||||
await this.persistDevice(device)
|
||||
}
|
||||
// Autres erreurs (réseau, timeout, 9002+) → gpnStatus inchangé
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import type { DeviceSnapshot } from '../domain/device/device.js'
|
||||
import type { Device } from '../domain/device/device.js'
|
||||
import { DeviceParameter } from '../domain/device/device_parameter.js'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const tr181Catalog: Array<{ path: string; writable: boolean; deviceClass: string }> =
|
||||
@@ -7,6 +9,9 @@ const tr181Catalog: Array<{ path: string; writable: boolean; deviceClass: string
|
||||
|
||||
// Index chargé une fois au démarrage — O(1) lookup
|
||||
const catalogIndex = new Map(tr181Catalog.map((e) => [e.path, e.writable]))
|
||||
const catalogWritableIndex = new Set(
|
||||
tr181Catalog.filter((e) => e.writable).map((e) => e.path)
|
||||
)
|
||||
|
||||
/** Remplace les segments numériques par {i} pour matcher les entrées du catalogue */
|
||||
export function normalizePath(path: string): string {
|
||||
@@ -46,3 +51,27 @@ export function resolveWritability(snapshot: DeviceSnapshot, paramPath: string):
|
||||
if (gpnStatus === 'unsupported') return { writable: true, source: 'default' }
|
||||
return { writable: null, source: 'unknown' }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reclassify device properties as parameters using the TR-181 catalog.
|
||||
* Properties that are writable per the catalog are moved to parameters.
|
||||
* Should be called after updateFromValues when gpnStatus is 'unsupported'.
|
||||
*/
|
||||
export function reclassifyDeviceFromCatalog(device: Device): number {
|
||||
const properties = device.getProperties()
|
||||
let reclassified = 0
|
||||
|
||||
for (const prop of properties) {
|
||||
const normalized = normalizePath(prop.name)
|
||||
if (catalogWritableIndex.has(normalized)) {
|
||||
const snap = prop.toSnapshot()
|
||||
device.setParameter(
|
||||
new DeviceParameter(snap.name, snap.value, snap.type, snap.createdAt, snap.updatedAt, snap.notification, snap.accessList)
|
||||
)
|
||||
;(device as any)._properties.delete(prop.name)
|
||||
reclassified++
|
||||
}
|
||||
}
|
||||
|
||||
return reclassified
|
||||
}
|
||||
Reference in new issue
Block a user