Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: GET request for all large community parts #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/Bird.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,21 @@ public function routesProtocol( $protocol ) {
}

public function routesProtocolLargeCommunityWildXYRoutes( $protocol, $x, $y ) {
$routesBlob = $this->run('show route all filter { if bgp_large_community ~ [( ' . ((int)$x) . ', ' . ((int)$y) . ', * )] then accept;} protocol ' . $protocol );
$routesBlob = $this->run('show route all filter { if bgp_large_community ~ [( ' . ((int)$x) . ', ' . ((int)$y) . ', * )] then accept; else reject;} protocol ' . $protocol );

return ( new RoutesParser($routesBlob ) )->parse();
}
public function routesProtocolLargeCommunityWildXYZRoutes( $protocol, $x, $y, $z ) {
$routesBlob = $this->run('show route all filter { if bgp_large_community ~ [( ' . ((int)$x) . ', ' . ((int)$y) . ', '. ((int)$z) .')] then accept; else reject;} protocol ' . $protocol );

return ( new RoutesParser($routesBlob ) )->parse();
}

public function routesProtocolLargeCommunityWildXYZCount( $protocol, $x, $y, $z ) {
$routesCountBlob = $this->run('show route all filter { if bgp_large_community ~ [( ' . ((int)$x) . ', ' . ((int)$y) . ', '. ((int)$z) .')] then accept; else reject;} protocol ' . $protocol . ' count' );

return ( new RoutesCountParser($routesCountBlob ) )->parse();
}
public function routesProtocolCount( $protocol ) {
$routesCountBlob = $this->run('show route protocol ' . $protocol . ' count');

Expand All @@ -134,7 +144,10 @@ public function routesExportCount( $protocol ) {


public function routesTable( $table ) {
$routesBlob = $this->run('show route table ' . $table . ' all');
$protocol = substr_replace($table,"b",0,1);
#dd( $protocol );
$routesBlob = $this->run('show route table ' . $table . ' all protocol '.$protocol);
#dd( $routesBlob );

return ( new RoutesParser($routesBlob ) )->parse();
}
Expand Down
49 changes: 49 additions & 0 deletions app/Http/Controllers/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ private function getProtocolLargeCommunityWildXYRoutes($protocol,$x,$y) {
}
return $routes;
}
private function getProtocolLargeCommunityWildXYZRoutes($protocol,$x,$y,$z) {
if( !$this->cacheDisabled && $routes = Cache::get( $this->cacheKey() . 'routes-protocols-lcwild-xyz-' . $protocol . '-' . $x . '-' . $y . '-' . $z) ) {
$this->cacheUsed = true;
} else {
$routes = app('Bird')->routesProtocolLargeCommunityWildXYZRoutes($protocol,$x,$y,$z);
Cache::put($this->cacheKey() . 'routes-protocols-lcwild-xyz-' . $protocol . '-' . $x . '-' . $y . '-' . $z, $routes, env( 'CACHE_ROUTES', 5 ) );
}
return $routes;
}


private function getProtocolLargeCommunityWildXYZCount($protocol,$x,$y,$z) {
if( !$this->cacheDisabled && $routesCount = Cache::get( $this->cacheKey() . 'routes-protocols-lcwild-xyz-' . $protocol . '-count' . '-' . $x . '-' . $y . '-' . $z ) ) {
$this->cacheUsed = true;
} else {
$routesCount = app('Bird')->routesProtocolLargeCommunityWildXYZCount($protocol,$x,$y,$z);
Cache::put($this->cacheKey() .'routes-protocols-lcwild-xyz-' . $protocol . '-count' . '-' . $x . '-' . $y . '-' . $z, $routesCount, env( 'CACHE_ROUTES', 5 ) );
}

if( $routesCount['routes'] === null ) {
about( 500, 'Could not get route count for protocol ' . $protocol );
}
return $routesCount;
}

private function getProtocolRoutesCount($protocol) {
if( !$this->cacheDisabled && $routesCount = Cache::get( $this->cacheKey() . 'routes-protocols-' . $protocol . '-count' ) ) {
Expand Down Expand Up @@ -136,6 +160,31 @@ public function protocolLargeCommunityWildXY( $protocol, $x, $y )
return $this->verifyAndSendJSON( 'routes', $this->getProtocolLargeCommunityWildXYRoutes($protocol,$x,$y), ['from_cache' => $this->cacheUsed, 'ttl_mins' => env( 'CACHE_ROUTES', 5 ) ] );
}

#
# show route all filter { if bgp_large_community ~ [( 2128, 1101, 1 )] then accept;} protocol pb_as1213_vli222_ipv4
public function protocolLargeCommunityWildXYZ( $protocol, $x, $y, $z )
{
$x = (int)$x;
$y = (int)$y;
$z = (int)$z;

// let's make sure the protocol is valid:
if( !in_array( $protocol, $this->getSymbols()['protocol'] ) || !$x || !$y || !$z ) {
abort( 404, "Invalid protocol" );
}

return $this->verifyAndSendJSON( 'routes', $this->getProtocolLargeCommunityWildXYZRoutes($protocol,$x,$y, $z), ['from_cache' => $this->cacheUsed, 'ttl_mins' => env( 'CACHE_ROUTES', 5 ) ] );
}

public function protocolLargeCommunityWildXYZCount($protocol,$x,$y,$z)
{
// let's make sure the protocol is valid:
if( !in_array( $protocol, $this->getSymbols()['protocol'] ) ) {
abort( 404, "Invalid protocol" );
}

return $this->verifyAndSendJSON( 'count', $this->getProtocolLargeCommunityWildXYZCount($protocol,$x,$y,$z), ['from_cache' => $this->cacheUsed, 'ttl_mins' => env( 'CACHE_ROUTES', 5 ) ] );
}

public function exportCount($protocol)
{
Expand Down
2 changes: 2 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@

// Get wildcard large communities in protocol tabe of form ( x, y, * )
$app->get('api/routes/lc-zwild/protocol/{protocol}/{x}/{y}', 'Routes@protocolLargeCommunityWildXY' );
$app->get('api/routes/lc-zwild/protocol/{protocol}/{x}/{y}/{z}', 'Routes@protocolLargeCommunityWildXYZ' );
$app->get('api/routes/count/lc-zwild/protocol/{protocol}/{x}/{y}/{z}', 'Routes@protocolLargeCommunityWildXYZCount');


$throttle = env('THROTTLE_PER_MIN',20);
Expand Down