Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6727b72

Browse files
committed
Vagrant looking glass and more router testbed
1 parent e4d8618 commit 6727b72

13 files changed

Lines changed: 574 additions & 43 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace IXP\Console\Commands\Router;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\DB;
7+
use IXP\Models\Router;
8+
9+
class ResetAllUpdateTimestampsCommand extends Command
10+
{
11+
protected $signature = 'router:reset-all-update-timestamps';
12+
13+
protected $description = 'Resets all router update timestamps to null';
14+
15+
public function handle(): void
16+
{
17+
DB::table('routers')->update( [
18+
'last_update_started' => null,
19+
'last_updated' => null,
20+
]);
21+
}
22+
}

app/Console/Commands/Utils/ExpungeLogs.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class ExpungeLogs extends IXPCommand
5555
*
5656
* @var string
5757
*/
58-
protected $signature = 'utils:expunge-logs';
58+
protected $signature = 'utils:expunge-logs {--all}';
5959

6060
/**
6161
* The console command description.
6262
*
6363
* @var string
6464
*/
65-
protected $description = 'This command will delete old data from database tables > 6 months old';
65+
protected $description = 'This command will delete old data from database tables > 6 months old (or all if --all set)';
6666

6767
/**
6868
* Execute the console command.
@@ -71,7 +71,11 @@ class ExpungeLogs extends IXPCommand
7171
*/
7272
public function handle()
7373
{
74-
$sixmonthsago = now()->subMonths(6)->format( 'Y-m-d 00:00:00' );
74+
if( $this->option('all') ) {
75+
$sixmonthsago = now()->addDay();
76+
} else {
77+
$sixmonthsago = now()->subMonths( 6 )->format( 'Y-m-d 00:00:00' );
78+
}
7579

7680
// Deleting user login logs older than 6 months
7781
$this->isVerbosityVerbose() && $this->output->write('Expunging user login records > 6 months...', false );
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace IXP\Console\Commands\Vagrant;
4+
5+
use Illuminate\Console\Command;
6+
use IXP\Models\Router;
7+
use IXP\Models\VlanInterface;
8+
9+
class GenerateBirdseyeConfigurationsCommand extends Command
10+
{
11+
protected $signature = 'vagrant:generate-birdseye-configurations {--directory=/srv/birdseye}';
12+
13+
protected $description = 'Vagrant development tool - generate birdseye configurations for all routers';
14+
15+
public function handle(): void
16+
{
17+
// directory exists and writable?
18+
if( !is_dir( $this->option( 'directory' ) ) || !is_writable( $this->option( 'directory' ) ) ) {
19+
$this->error( "Directory path {$this->option('directory')} is not writable" );
20+
exit( 1 );
21+
}
22+
23+
foreach( Router::get() as $router ) {
24+
25+
file_put_contents( $this->option( 'directory' ) . '/birdseye-' . $router->handle . '.env',
26+
27+
"#
28+
# Bird's Eye - Vagrant generated configuration
29+
30+
BIRDC=\"/usr/bin/sudo /srv/birdseye/bin/birdc -2 -s /var/run/bird/bird-{$router->handle}.ctl\"
31+
CACHE_DRIVER=array
32+
MAX_ROUTES=100000
33+
"
34+
35+
);
36+
37+
}
38+
}
39+
}
40+

app/Console/Commands/Vagrant/GenerateClientRouterConfigurationsCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public function handle(): void
2525

2626
foreach( $vlis as $vli ) {
2727

28+
// skip route servers, collector and as112
29+
if( in_array( $vli->virtualInterface->customer->autsys, [ 112, 65500, 65501 ] ) ) { continue; }
30+
31+
32+
33+
34+
2835
$this->info( "Generating route server client for {$vli->virtualInterface->customer->name} / {$vli->vlan->name}" );
2936

3037
$confName = "as{$vli->virtualInterface->customer->autsys}-"

app/Http/Middleware/Services/LookingGlass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function handle( Request $r, Closure $next )
149149
private function authorise( Router $router ): bool
150150
{
151151
/** @var User $us */
152-
$us = Auth::getUser();
152+
$us = Auth::user();
153153

154154
if( $router->authorise( Auth::check() ? $us->privs() : User::AUTH_PUBLIC ) ) {
155155
return true;

resources/views/api/v4/router/collector/bird2/filter-transit-networks.foil.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@
5757

5858
<?php if( count( $no_transit_asns ) === 0 ): ?>
5959
# .env file has disabled transit ASN filtering with an empty IXP_NO_TRANSIT_ASNS_OVERRIDE setting:
60-
function filter_has_transit_path()
60+
function filter_has_transit_path() -> bool
6161
{
6262
return false;
6363
}
6464

6565
<?php else: ?>
6666
define TRANSIT_ASNS = [ <?= implode( ', ', array_keys( $no_transit_asns ) ) ?> ];
6767

68-
function filter_has_transit_path()
68+
function filter_has_transit_path() -> bool
6969
int set transit_asns;
7070
{
7171
transit_asns = TRANSIT_ASNS;

resources/views/vagrant/router-client.foil.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@
3636
}
3737

3838

39-
<?php foreach( Router::where('protocol', 4)->where('vlan_id', $vli->vlanid)->get() as $r ):
40-
41-
if( $vli->virtualInterface->customer->autsys == $r->asn ) { continue; }
42-
43-
?>
39+
<?php foreach( Router::where('protocol', 4)->where('vlan_id', $vli->vlanid)->get() as $r ): ?>
4440

4541
# <?= $r->name ?>
4642

@@ -77,11 +73,7 @@
7773

7874

7975

80-
<?php foreach( Router::where('protocol', 6)->where('vlan_id', $vli->vlanid)->get() as $r ):
81-
82-
if( $vli->virtualInterface->customer->autsys == $r->asn ) { continue; }
83-
84-
?>
76+
<?php foreach( Router::where('protocol', 6)->where('vlan_id', $vli->vlanid)->get() as $r ): ?>
8577

8678
# <?= $r->name ?>
8779

tools/vagrant/bootstrap.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ sed -i 's/127.0.0.1 localhost/127.0.0.1 localhost swi1-fac1-1 swi1-fac2-1 swi2-f
196196

197197
####################################################################################
198198
#######
199-
####### Route Servers / Collectors
199+
####### Route Servers / Collectors / AS112 / Clients
200200

201201
apt-get -y install bird2
202202
/usr/bin/systemctl stop bird.service
@@ -216,12 +216,56 @@ mysql --defaults-extra-file=/etc/mysql/ixpmanager.cnf --skip-column-names --sil
216216
-e 'SELECT CONCAT( peering_ip, " ", handle ) FROM routers' >> /etc/hosts
217217

218218
/vagrant/tools/vagrant/scripts/rs-api-reconfigure-all.sh
219+
/vagrant/tools/vagrant/scripts/rc-reconfigure.sh
220+
/vagrant/tools/vagrant/scripts/as112-reconfigure-bird2.sh
219221

220222
php /vagrant/artisan vagrant:generate-client-router-configurations
221223
chmod a+x /srv/clients/start-reload-clients.sh
222224
/srv/clients/start-reload-clients.sh
223225

224226

227+
####################################################################################
228+
#######
229+
####### Birdseye Looking Glass
230+
#######
231+
232+
git clone https://github.com/inex/birdseye.git /srv/birdseye
233+
cd /srv/birdseye
234+
git checkout php83
235+
chown -R vagrant: /srv/birdseye
236+
237+
238+
cat >/etc/apache2/sites-enabled/birdseye.conf <<END_APACHE
239+
Listen 81
240+
241+
<VirtualHost *:81>
242+
DocumentRoot /srv/birdseye/public
243+
244+
<Directory /srv/birdseye/public>
245+
Options FollowSymLinks
246+
AllowOverride None
247+
Require all granted
248+
249+
RewriteEngine On
250+
RewriteCond %{REQUEST_FILENAME} -s [OR]
251+
RewriteCond %{REQUEST_FILENAME} -l [OR]
252+
RewriteCond %{REQUEST_FILENAME} -d
253+
RewriteRule ^.*$ - [NC,L]
254+
RewriteRule ^.*$ /index.php [NC,L]
255+
</Directory>
256+
257+
ErrorLog ${APACHE_LOG_DIR}/birdseye-error.log
258+
CustomLog ${APACHE_LOG_DIR}/birdseye-access.log combined
259+
</VirtualHost>
260+
261+
END_APACHE
262+
263+
systemctl restart apache2.service
264+
265+
php /vagrant/artisan vagrant:generate-birdseye-configurations
266+
echo -e "\nvagrant ALL=(ALL) NOPASSWD: /srv/birdseye/bin/birdc\n" >>/etc/sudoers
267+
268+
225269

226270
####################################################################################
227271
#######

tools/vagrant/envfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ IXP_AS112_UI_ACTIVE=true
100100
#
101101
## Enable the UI for route server community-based filtering by uncommenting this line:
102102
## IXP_FE_FRONTEND_DISABLED_RS_FILTERS=false
103+
104+
IXP_FE_FRONTEND_DISABLED_LOOKING_GLASS=false
105+
103106
#
104107
########################################################################################
105108
#### Graphing - see https://docs.ixpmanager.org/grapher/introduction
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#! /usr/bin/env bash
2+
#
3+
# Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee.
4+
# All Rights Reserved.
5+
#
6+
# This file is part of IXP Manager.
7+
#
8+
# IXP Manager is free software: you can redistribute it and/or modify it
9+
# under the terms of the GNU General Public License as published by the Free
10+
# Software Foundation, version 2.0 of the License.
11+
#
12+
# IXP Manager is distributed in the hope that it will be useful, but WITHOUT
13+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+
# more details.
16+
#
17+
# You should have received a copy of the GNU General Public License v2.0
18+
# along with IXP Manager. If not, see:
19+
#
20+
# http://www.gnu.org/licenses/gpl-2.0.html
21+
#
22+
# Barry O'Donovan <[email protected]> 2016
23+
24+
# Example script for updating AS112 Bird BGP configs
25+
26+
27+
# For keys, see: http://docs.ixpmanager.org/features/api/
28+
29+
30+
KEY="r8sFfkGamCjrbbLC12yIoCJooIRXzY9CYPaLVz92GFQyGqLq"
31+
BIRDBIN="/usr/sbin/bird"
32+
33+
URL="http://127.0.0.1/api/v4/router/gen-config"
34+
URL_DONE="http://127.0.0.1/api/v4/router/updated"
35+
ETCPATH="/usr/local/etc/bird"
36+
RUNPATH="/var/run/bird"
37+
LOGPATH="/var/log/bird"
38+
BIN="/usr/sbin/bird"
39+
40+
mkdir -p $ETCPATH
41+
mkdir -p $LOGPATH
42+
mkdir -p $RUNPATH
43+
44+
if [[ -n $1 && $1 = '--quiet' ]]; then
45+
export QUIET=1
46+
else
47+
export QUIET=0
48+
echo -en "\nIXP AS112 BGPd Lisenters\n==============================\n\n"
49+
echo -e "Verbose mode enabled. Issue --quiet for non-verbose mode (--debug also available)\n"
50+
fi
51+
52+
if [[ -n $1 && $1 = '--debug' ]]; then
53+
export QUIET=1
54+
export DEBUG=1
55+
else
56+
export DEBUG=0
57+
fi
58+
59+
function log {
60+
if [[ $QUIET -eq 0 && $DEBUG -eq 0 ]]; then
61+
echo -en $1
62+
fi
63+
}
64+
65+
# These are the handles as configured in your IXP Manager - see: http://docs.ixpmanager.org/features/routers/
66+
#
67+
# This script assumes v6 versions end in -ipv6
68+
69+
for handle in as112-vix1-ipv4 as112-vix1-ipv6 as112-vix2-ipv4 as112-vix2-ipv6; do
70+
71+
log "Instance for ${handle}:\tConfig: "
72+
73+
cmd="curl --fail -s -H \"X-IXP-Manager-API-Key: ${KEY}\" ${URL}/${handle} >${ETCPATH}/bird-${handle}.conf"
74+
75+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
76+
eval $cmd
77+
78+
if [[ $? -eq 0 ]]; then
79+
log "DONE \tDaemon: "
80+
else
81+
log "ERROR\n"
82+
continue
83+
fi
84+
85+
# are we running or do we need to be started?
86+
cmd="${BIN}c -s ${RUNPATH}/bird-${handle}.ctl configure"
87+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
88+
eval $cmd &>/dev/null
89+
90+
if [[ $? -eq 0 ]]; then
91+
log "RECONFIGURED \tIXP Manager Updated:"
92+
else
93+
cmd="${BIN} -c ${ETCPATH}/bird-${handle}.conf -s ${RUNPATH}/bird-${handle}.ctl"
94+
95+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
96+
eval $cmd &>/dev/null
97+
98+
if [[ $? -eq 0 ]]; then
99+
log "STARTED \tIXP Manager Updated:"
100+
else
101+
log "ERROR\n"
102+
continue
103+
fi
104+
fi
105+
106+
# tell IXP Manager the router has been updated:
107+
cmd="curl -s -X POST -H \"X-IXP-Manager-API-Key: ${KEY}\" ${URL_DONE}/${handle} >/dev/null"
108+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
109+
eval $cmd
110+
111+
if [[ $? -eq 0 ]]; then
112+
log "DONE"
113+
else
114+
log "ERROR\n"
115+
continue
116+
fi
117+
118+
log "\n"
119+
done
120+
121+
log "\n"

0 commit comments

Comments
 (0)