Skip to content
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
25 changes: 25 additions & 0 deletions tools/perl-lib/IXPManager/ixpmanager.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,29 @@
# debug = 1
apikey = VeryLongAPIKeyFromIXPManager
apibaseurl = http://www.example.com/ixp/api/v4

# use configured MAC table instead of learned MAC table?
# macdbtype = configured

# If resold VLANs are not in IXP Manager, do we map VLANs for translations/resold customers?

map_vlans = 0

# If map_vlans is enabled, query to translate VLANs.
# query should return two fields: pvlan (resold vlan) and vlan (peering vlan)
#
# Example: Extract VLAN id from subinterface names e.g. Ethernet15/1.501
# for all resold customers. Map to actual peering VLAN as configured in IXPM.
#
map_vlan_query = SELECT DISTINCT SUBSTRING_INDEX(sp.name, '.', -1) AS pvlan, v.number as vlan \
FROM switchport sp \
INNER JOIN physicalinterface pi ON pi.switchportid = sp.id \
INNER JOIN virtualinterface vi ON pi.virtualinterfaceid = vi.id \
INNER JOIN cust c ON vi.custid = c.id \
INNER JOIN vlaninterface vli ON vli.virtualinterfaceid = vi.id \
INNER JOIN vlan v ON vli.vlanid = v.id \
WHERE c.reseller > 0 AND \
v.peering_matrix = 1 AND \
sp.name LIKE '%.%'

</ixp>
46 changes: 45 additions & 1 deletion tools/runtime/sflow/sflow-detect-ixp-bgp-sessions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# sflow-detect-ixp-bgp-sessions
#
# Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee.
# Copyright (C) 2009 - 2025 Internet Neutral Exchange Association Company Limited By Guarantee.
# All Rights Reserved.
#
# This file is part of IXP Manager.
Expand Down Expand Up @@ -47,6 +47,8 @@ my $dbh = $ixp->{db};

my $debug = defined($ixp->{ixp}->{debug}) ? $ixp->{ixp}->{debug} : 0;
my $insanedebug = 0;
my $map_vlans = defined($ixp->{ixp}->{map_vlans}) ? $ixp->{ixp}->{map_vlans} : 0;
my $map_vlan_query = $ixp->{ixp}->{map_vlan_query};
my $sflowtool = defined($ixp->{ixp}->{sflowtool}) ? $ixp->{ixp}->{sflowtool} : '/usr/bin/sflowtool';
my $sflowtool_opts = defined($ixp->{ixp}->{sflowtool_bgp_opts}) ? $ixp->{ixp}->{sflowtool_bgp_opts} : '-l';
my $timer_period = 600;
Expand All @@ -69,6 +71,13 @@ if ($insanedebug) {

my $ipmappings = reload_ipmappings($dbh);

my $vlan_mappings;

if ($map_vlans) {
$vlan_mappings = reload_vlan_mappings($dbh,$map_vlan_query);
$debug && print Dumper ($vlan_mappings);
}

my $execute_periodic = 0;
my $quit_after_periodic = 0;

Expand Down Expand Up @@ -137,6 +146,13 @@ while (<SFLOWTOOL>) {

# we're also only interested in ip addresses that have a database match
if ($ipmappings->{$ipprotocol}->{$srcip} && $ipmappings->{$ipprotocol}->{$dstip}) {

# if enabled, correct VLAN if there are VLAN translations e.g. for resold customers:
if ($vlan_mappings->{$vlan}->{'vlan'}) {
print STDERR " [VLAN mapping: VLAN $vlan -> $vlan_mappings->{$vlan}->{'vlan'}]" if ($debug);
$vlan = $vlan_mappings->{$vlan}->{'vlan'};
}

print STDERR " database updated" if ($debug);
if (!$sth->execute($ipmappings->{$ipprotocol}->{$srcip}, $ipmappings->{$ipprotocol}->{$dstip}, $ipprotocol, $vlan, $agent)) {
print STDERR " unsuccessfully" if ($debug);
Expand All @@ -162,8 +178,14 @@ while (<SFLOWTOOL>) {
}
$execute_periodic = 0;
$ipmappings = reload_ipmappings($dbh);

if ($map_vlans) {
$vlan_mappings = reload_vlan_mappings($dbh,$map_vlan_query);
}

$debug && print STDERR "DEBUG: periodic reload completed at ".time()."\n";
$debug && print Dumper ($ipmappings);
$debug && print Dumper ($vlan_mappings);

if (time() - $lastdailyrun > 86400) {
$lastdailyrun = time();
Expand Down Expand Up @@ -227,3 +249,25 @@ sub reload_ipmappings

return $mapping;
}

#
# VLAN translation mappings
#
sub reload_vlan_mappings {

my ($d,$sql) = @_;

return undef unless ($sql);

my ($s, $mapping);

$debug && print STDERR "DEBUG: sql $sql\n";

$s = $d->prepare("$sql");
$s->execute();

$mapping = $s->fetchall_hashref('pvlan');

return $mapping;

}