diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/juniper.php | 24 | ||||
-rw-r--r-- | routers/router.php | 16 |
2 files changed, 27 insertions, 13 deletions
diff --git a/routers/juniper.php b/routers/juniper.php index 2a81663..14f431e 100644 --- a/routers/juniper.php +++ b/routers/juniper.php @@ -23,15 +23,17 @@ require_once 'router.php'; require_once 'utils.php'; final class Juniper extends Router { - protected function build_command($command, $parameters) { + protected function build_commands($command, $parameters) { + $commands = array(); + switch ($command) { case 'bgp': if (match_ipv4($parameters)) { - $complete_command = 'show route '.$parameters. - ' table inet.0 protocol bgp active-path | no-more'; + $commands[] = 'show route '.$parameters. + ' protocol bgp table inet.0 active-path | no-more'; } else if (match_ipv6($parameters)) { - $complete_command = 'show route '.$parameters. - ' table inet6.0 protocol bgp active-path | no-more'; + $commands[] = 'show route '.$parameters. + ' protocol bgp table inet6.0 active-path | no-more'; } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); } @@ -39,7 +41,10 @@ final class Juniper extends Router { case 'as-path-regex': if (match_aspath_regex($parameters)) { - $complete_command = 'show route aspath-regex '.$parameters.' | no-more'; + $commands[] = 'show route aspath-regex '.$parameters. + ' protocol bgp table inet.0 | no-more'; + $commands[] = 'show route aspath-regex '.$parameters. + ' protocol bgp table inet6.0 | no-more'; } else { throw new Exception('The parameter is not an AS-Path regular expression like ".*XXXX YYYY.*".'); } @@ -47,7 +52,10 @@ final class Juniper extends Router { case 'as': if (match_as($parameters)) { - $complete_command = 'show route aspath-regex .*'.$parameters.'.* | no-more'; + $commands[] = 'show route aspath-regex ^'.$parameters. + '$ protocol bgp table inet.0 | no-more'; + $commands[] = 'show route aspath-regex ^'.$parameters. + '$ protocol bgp table inet6.0 | no-more'; } else { throw new Exception('The parameter is not an AS number.'); } @@ -76,7 +84,7 @@ final class Juniper extends Router { throw new Exception('Command not supported.'); } - return $complete_command; + return $commands; } } diff --git a/routers/router.php b/routers/router.php index 303b194..cb213da 100644 --- a/routers/router.php +++ b/routers/router.php @@ -39,11 +39,11 @@ abstract class Router { } } - protected abstract function build_command($command, $parameters); + protected abstract function build_commands($command, $parameters); public function send_command($command, $parameters) { try { - $complete_command = $this->build_command($command, $parameters); + $commands = $this->build_commands($command, $parameters); } catch (Exception $e) { throw $e; } @@ -52,13 +52,19 @@ abstract class Router { try { $auth->connect(); - $data = $auth->send_command($complete_command); + + foreach ($commands as $selected) { + $data .= $auth->send_command($selected); + } } catch (Exception $e) { throw $e; } finally { $auth->disconnect(); - log_to_file('[client: '.$this->requester.'] '.$this->config['host'].'> '. - $complete_command); + + foreach ($commands as $selected) { + log_to_file('[client: '.$this->requester.'] '.$this->config['host'].'> '. + $selected); + } } return $data; |