Creating a virtual parameter for fetching PPPoE across different ONTs

Hi,

I followed the docs and Wiki in github to create a virtual parameter to get PPPoE username for different model of ONTs.

I have create a virtual parameter called FirstWANDevicePPPoEUsername

// FirstWANDevicePPPoEUsername - Gets PPPoE username from first WAN device
// Parameter name to use in index.page.yml: FirstWANDevicePPPoEUsername

let username = "";
let d = declare(
  "Device.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.Username",
  { value: Date.now() }
);

log(d);

if (d.size) {
  for (let p of d) {
    if (p.value[0]) {
      username = p.value[0];
      break;
    }
  }
}
return { writable: false, value: [username, "xsd:string"] };

Then following the guide I created a provisioning called Refresh_VParams

declare("VirtualParameters.*", {value: Date.now()});

then created a Preset using the same provisioning script Refresh_VParams without any other parameters (i.e precondition etc)

However when I go to a device and search for FirstWANDevicePPPoEUsername or VirtualParameter I don’t see anything. I waited and several inform request came from ONT and even summned couple of times.

What am I doing wrong?

What you have should work. Are you sure that the Refresh_VParams script is being run? Add a call to log('in refresh_vparams'); to the code and then check in the genieacs-cwmp-access.log file for that line.

Another thing to try is:

declare("VirtualParameters.*", { value: Date.now(), path: Date.now() });

it does execute but d.size is always undefined (and JSON.stringify(d) just prints {}) even if just do this

let d = declare(
  "Device.WANDevice",
  { value: Date.now() }
);

or

let d = declare(
  "Device.WANDevice.1",
  { value: Date.now() }
);

not sure what is the problem. I could see the Device.WANDevice.1 exists in Device Details page.

I am trying to get the list of usernames set on WANPPPConnections regardless of WAN interface numbering set by the device (i.e. Calix ONT sets WANDevice.5 and Huawei sets WANDevice.1 so on)

Those two script blocks you posted would never work. You aren’t asking for anything specific, you are asking for the instance of an object, instead of a parameter.

While putting together the script below, I see what you are doing wrong now. You appear to be mixing two different version of parameter paths. InternetGatewayDevice has WANDevice and is v1. Device is v2, and does not have WANDevice.

Here is the script I use for my username vparam:

let result = '';

if ('value' in args[1]) {
    result = args[1].value[0];
} else {
    const keys = [
        'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.Username',
        'Device.PPP.Interface.*.Username'
    ];

    result = getParameterValue(keys);
}

return {writable: true, value: [result, "xsd:string"]};

function getParameterValue(keys) {
    for (let key of keys) {
        let d = declare(key, {path: Date.now() - (120 * 1000), value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return 'UNKNOWN';
}