1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

introduced tests for neighbors monitoring

This commit is contained in:
Massimo Candela
2021-04-30 15:47:30 +02:00
parent 133ec68575
commit 349126568e
7 changed files with 397 additions and 3 deletions

View File

@@ -15,12 +15,13 @@
},
"scripts": {
"babel": "./node_modules/.bin/babel",
"test": "npm run test-core && npm run test-generate && npm run test-reports && npm run test-rpki",
"test": "npm run test-core && npm run test-generate && npm run test-reports && npm run test-rpki && npm run test-neighbor",
"test-core": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/*.js --require @babel/register && rm -rf volumetests/",
"test-reports": "./node_modules/.bin/mocha --exit tests/reports_tests/testReportSyslog.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/reports_tests/testsReportHttp.js --require @babel/register",
"test-proxy": "./node_modules/.bin/mocha --exit tests/proxy_tests/*.js --require @babel/register",
"test-generate": "./node_modules/.bin/mocha --exit tests/generate_tests/*.js --require @babel/register",
"test-kafka": "./node_modules/.bin/mocha --exit tests/kafka_tests/*.js --require @babel/register",
"test-neighbor": "./node_modules/.bin/mocha --exit tests/neighbor_tests/*.js --require @babel/register",
"test-npm": "./node_modules/.bin/mocha --exit tests/npm_tests/*.js --require @babel/register",
"test-rpki": "./node_modules/.bin/mocha --exit tests/rpki_tests/tests.default.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-missing-roas.js --require @babel/register && rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-roas.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.api.js --require @babel/register",
"build": "./build.sh",

View File

@@ -36,7 +36,7 @@ import Connector from "./connector";
import {AS, Path} from "../model";
import ipUtils from "ip-sub";
export default class ConnectorTest extends Connector{
export default class ConnectorTest extends Connector {
constructor(name, params, env) {
super(name, params, env);
@@ -445,6 +445,78 @@ export default class ConnectorTest extends Connector{
}
];
break;
case "path-poisoning":
updates = [
{
data: {
announcements: [{
prefixes: ["9.5.4.3/22"], // Path not ok but prefix not monitored
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 100, 101, 106]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["99.5.4.3/22"], // Monitored but path ok
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 100, 101, 104]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["99.5.4.3/22"], // Monitored, path with wrong downstream
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 100, 101, 106]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["99.5.4.3/22"], // Monitored, path with wrong upstream
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 30, 101, 104]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["99.5.4.3/22"], // Monitored, path with empty downstream ok
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 80]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["99.5.4.3/22"], // Monitored, path with empty downstream not ok
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [98, 99, 80, 100]
},
type: "ris_message"
}
];
break;
default:
return;
}

View File

@@ -64,7 +64,6 @@ export default class MonitorPathPoisoning extends Monitor {
monitor = (message) =>
new Promise((resolve, reject) => {
const path = message.path;
for (let monitoredAs of this.monitored) {

View File

@@ -0,0 +1,186 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, NTT Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const chai = require("chai");
const fs = require("fs");
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);
const expect = chai.expect;
const volume = "volumetests/";
const asyncTimeout = 120000;
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";
// Prepare test environment
if (!fs.existsSync(volume)) {
fs.mkdirSync(volume);
} else {
fs.rmdirSync(volume, { recursive: true });
fs.mkdirSync(volume);
}
fs.copyFileSync("tests/neighbor_tests/config.test.yml", volume + "config.test.yml");
fs.copyFileSync("tests/neighbor_tests/prefixes.test.yml", volume + "prefixes.test.yml");
fs.copyFileSync("tests/neighbor_tests/groups.test.yml", volume + "groups.test.yml");
const worker = require("../../index");
const pubSub = worker.pubSub;
describe("Alerting", function () {
it("path-poisoning monitoring reporting", function (done) {
const expectedData = {
"101-30": {
"id": "101-30",
"truncated": false,
"origin": "path-poisoning",
"affected": 101,
"message": "A new upstream of AS101 has been detected: AS30",
"data": [{
"affected": 101,
"matchedRule": {
"asn": [101],
"group": "default",
"groupd": "default",
"upstreams": [100],
"downstreams": [104]
},
"matchedMessage": {
"type": "announcement",
"prefix": "99.5.4.3/22",
"peer": "124.0.0.3",
"path": [98, 99, 30, 101, 104],
"originAS": [104],
"nextHop": "124.0.0.3",
"aggregator": null,
"timestamp": null,
"communities": []
},
"extra": {"side": "upstream", "neighbor": 30}
}]
},
"80-100": {
"id": "80-100",
"truncated": false,
"origin": "path-poisoning",
"affected": 80,
"message": "A new downstream of AS80 has been detected: AS100",
"data": [{
"affected": 80,
"matchedRule": {
"asn": [80],
"group": "default",
"groupd": "default",
"upstreams": [99],
"downstreams": null
},
"matchedMessage": {
"type": "announcement",
"prefix": "99.5.4.3/22",
"peer": "124.0.0.3",
"path": [98, 99, 80, 100],
"originAS": [100],
"nextHop": "124.0.0.3",
"aggregator": null,
"communities": []
},
"extra": {"side": "downstream", "neighbor": 100}
}]
},
"101-106": {
"id": "101-106",
"truncated": false,
"origin": "path-poisoning",
"affected": 101,
"message": "A new downstream of AS101 has been detected: AS106",
"data": [{
"affected": 101,
"matchedRule": {
"asn": [101],
"group": "default",
"groupd": "default",
"upstreams": [100],
"downstreams": [104]
},
"matchedMessage": {
"type": "announcement",
"prefix": "9.5.4.3/22",
"peer": "124.0.0.3",
"path": [98, 99, 100, 101, 106],
"originAS": [106],
"nextHop": "124.0.0.3",
"aggregator": null,
"communities": []
},
"extra": {"side": "downstream", "neighbor": 106}
}]
}
};
let pathPoisoningTestcompleted = false;
pubSub.subscribe("path-poisoning", (message, type) => {
if (!pathPoisoningTestcompleted) {
try {
message = JSON.parse(JSON.stringify(message));
const id = message.id;
expect(Object.keys(expectedData).includes(id)).to.equal(true);
expect(expectedData[id] != null).to.equal(true);
expect(message).to.containSubset(expectedData[id]);
expect(message).to.contain
.keys([
"latest",
"earliest"
]);
delete expectedData[id];
if (Object.keys(expectedData).length === 0) {
setTimeout(() => {
pathPoisoningTestcompleted = true;
done();
}, 5000);
}
} catch (error) {
pathPoisoningTestcompleted = true;
done(error);
}
}
});
pubSub.publish("test-type", "path-poisoning");
}).timeout(asyncTimeout);
});

View File

@@ -0,0 +1,109 @@
environment: test
connectors:
- file: connectorTest
name: tes
params:
testType: withdrawal
monitors:
- file: monitorHijack
channel: hijack
name: basic-hijack-detection
params:
thresholdMinPeers: 0
- file: monitorNewPrefix
channel: newprefix
name: prefix-detection
params:
thresholdMinPeers: 0
- file: monitorVisibility
channel: visibility
name: withdrawal-detection
params:
thresholdMinPeers: 4
- file: monitorPath
channel: path
name: path-matching
params:
thresholdMinPeers: 0
- file: monitorAS
channel: misconfiguration
name: asn-monitor
params:
thresholdMinPeers: 2
- file: monitorRPKI
channel: rpki
name: rpki-monitor
params:
thresholdMinPeers: 1
checkUncovered: true
- file: monitorROAS
channel: rpki
name: rpki-monitor
- file: monitorPathPoisoning
channel: path-poisoning
name: path-poisoning
params:
thresholdMinPeers: 0
reports:
- file: reportFile
channels:
- hijack
- newprefix
- visibility
- path
- misconfiguration
- rpki
params:
persistAlertData: false
alertDataDirectory: alertdata/
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
# This is an array (use new lines and dashes!)
monitoredPrefixesFiles:
- prefixes.test.yml
logging:
directory: logs
logRotatePattern: YYYY-MM-DD # Whenever the pattern changes, a new file is created and the old one rotated
maxRetainedFiles: 10
maxFileSizeMB: 15
compressOnRotation: true
checkForUpdatesAtBoot: true
persistStatus: true
volume: volumetests/
groupsFile: groups.test.yml
processMonitors:
- file: uptimeApi
params:
useStatusCodes: true
host: null
port: 8011
rpki:
vrpProvider: ntt
preCacheROAs: true
refreshVrpListMinutes: 15
markDataAsStaleAfterMinutes: 120
notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds
alertOnlyOnce: false
fadeOffSeconds: 10
checkFadeOffGroupsSeconds: 2
pidFile: bgpalerter.pid
multiProcess: false
maxMessagesPerSecond: 6000

View File

@@ -0,0 +1,4 @@
reportFile:
test:
- filename

View File

@@ -0,0 +1,23 @@
9.5.4.3/22:
description: test
asn: 101
ignoreMorespecifics: false
99.5.4.3/22:
description: test
asn: 101
ignoreMorespecifics: false
options:
monitorASns:
101:
groupd: default
upstreams:
- 100
downstreams:
- 104
80:
groupd: default
upstreams:
- 99
downstreams: