This article provides a script intended for use to clear a specific IP Pool in a router with BNG/PPPoE functions.
SLAX script:
version 1.1;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
var $arguments = {
<argument> {
<name> "pool";
<description> "Address Pool";
}
}
param $pool;
var $con = jcs:open();
match / {
<op-script-results> {
if ($pool = '') {
<xnm:error> {
<message> "Missing mandatory argument 'pool'";
}
}
else {
var $show_aaa_pool = {<command>"show network-access address-assignment pool " _ $pool;}
var $result = jcs:execute($con,$show_aaa_pool);
var $res_show_sub_cli_pppoe := {call get_show_sub_cli_pppoe();}
for-each($result/address-assignment-pool-table/address-assignment-pool-entry) {
var $sub_add = ip-address;
var $ppp_int = $res_show_sub_cli_pppoe//subscriber[ip-address == $sub_add]/interface;
call clear-ppp-sess($ppp_int);
}
}
}
}
template clear-ppp-sess ($ppp_int)
{
var $rpc2 = {<command>"clear pppoe sessions " _ $ppp_int;}
expr jcs:execute($con,$rpc2);
}
template get_show_sub_cli_pppoe() {
var $res= jcs:execute($con,<command>"show subscribers client-type pppoe");
for-each($res//subscriber/ip-address) {
<subscriber> {
<ip-address> .;
<interface> ../interface;
}
}
}
The slax script must be saved in /var/db/scripts/op using root and given read and execute permissions.
Under the configuration, add the next line,
set system scripts op file <.slax script>
If you have primary RE and backup RE, remember to create the slax file under the mentioned directory in the backup RE.
To execute the slax script:
-
Configure the "hold-down" to the IP pool to be cleared. Configuring Address-Assignment Pool Hold-Down
set access address-assignment pool <POOL> hold-down
-
Once the "hold-down" is set, execute the slax script.
[MASTER]
labroot@router> op <slax script.slax> pool <configured pool name>
The script will take approximately 5-10 minutes to clear a /20 IP pool.
The scope of this script is to work only for PPPoE v4 and dual stack subscribers.