Skip to content

Commit

Permalink
feat(tos): add DSCP and ECN values
Browse files Browse the repository at this point in the history
  • Loading branch information
christianpape authored and swachter committed Jan 14, 2021
1 parent 89e356f commit 0aa74c9
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"scripts": {
"changelog": "standard-changelog -i CHANGELOG.md -s -r 1",
"build": "webpack --mode production --env production",
"dev": "webpack --progress --colors",
"dev": "webpack --mode=development --progress",
"dist": "npm run lint && npm run test && npm run build && npm run docs",
"docs": "typedoc --out dist/docs src",
"watch": "webpack --progress --colors --watch",
Expand Down
246 changes: 201 additions & 45 deletions src/dao/FlowDAO.ts

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions test/dao/FlowDAO28.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {MockHTTP28} from '../rest/MockHTTP28';

declare const await, describe, beforeEach, it, xit, expect, jest, require;

import {Client} from '../../src/Client';

import {OnmsAuthConfig} from '../../src/api/OnmsAuthConfig';
import {OnmsServer} from '../../src/api/OnmsServer';

import {OnmsFlowTable} from '../../src/model/OnmsFlowTable';

import {FlowDAO} from '../../src/dao/FlowDAO';

/** @hidden */
// tslint:disable-next-line
const moment = require('moment');

const SERVER_NAME = 'Demo';
const SERVER_URL = 'http://demo.opennms.org/opennms/';
const SERVER_USER = 'demo';
const SERVER_PASSWORD = 'demo';

let opennms: Client, server, auth, mockHTTP, dao: FlowDAO;

describe('FlowDAO28', () => {
beforeEach((done) => {
auth = new OnmsAuthConfig(SERVER_USER, SERVER_PASSWORD);
const builder = OnmsServer.newBuilder(SERVER_URL).setName(SERVER_NAME).setAuth(auth);
server = builder.build();
mockHTTP = new MockHTTP28(server);
opennms = new Client(mockHTTP);
dao = new FlowDAO(mockHTTP);
Client.getMetadata(server, mockHTTP).then((metadata) => {
server = builder.setMetadata(metadata).build();
mockHTTP.server = server;
dao.server = server;
done();
});
});
it('FlowDao.getSummaryForDscp()', () => {
return dao.getSummaryForDscps().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('DSCP');
});
});
it('FlowDao.getSeriesForDscp()', () => {
return dao.getSeriesForDscps().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(2);
expect(series.timestamps.length).toEqual(44);
expect(series.values.length).toEqual(2);
expect(series.values[0].length).toEqual(44);
});
});
it('FlowDao.getDscpValues()', () => {
return dao.getDscpValues().then((toss) => {
expect([4, 5, 6]).toEqual(expect.arrayContaining(toss));
});
});
});
5 changes: 5 additions & 0 deletions test/rest/28.0.0/get/rest/flows/dscp/enumerate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
4,
5,
6
]
154 changes: 154 additions & 0 deletions test/rest/28.0.0/get/rest/flows/dscp/series.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"start": 1607940956998,
"end": 1607955356998,
"columns": [
{
"label": "0",
"ingress": true
},
{
"label": "0",
"ingress": false
}
],
"timestamps": [
1607942156998,
1607942456998,
1607942756998,
1607943056998,
1607943356998,
1607943656998,
1607943956998,
1607944256998,
1607944556998,
1607944856998,
1607945156998,
1607945456998,
1607945756998,
1607946056998,
1607946356998,
1607946656998,
1607946956998,
1607947256998,
1607947556998,
1607947856998,
1607948156998,
1607948456998,
1607948756998,
1607949056998,
1607949356998,
1607949656998,
1607949956998,
1607950256998,
1607950556998,
1607950856998,
1607951156998,
1607951456998,
1607951756998,
1607952056998,
1607952356998,
1607952656998,
1607952956998,
1607953256998,
1607953556998,
1607953856998,
1607954156998,
1607954456998,
1607954756998,
1607955056998
],
"values": [
[
1126.0,
38.273377724105075,
11500.678613767048,
31009.67861376705,
12705.24935385196,
31395.8446645343,
12227.275376355543,
31549.0,
11936.904111690425,
33748.875212849656,
14540.683422603217,
31372.714726099814,
12683.230929595637,
30884.6942125626,
3626.8551016754136,
1700.7184733761533,
14831.362037871877,
38899.89762710233,
19372.159324210163,
38441.400083860295,
19209.29963908182,
38190.678372557464,
17839.446723367757,
38006.12174321439,
51632.46944732391,
42197.767553104495,
18971.36278650359,
32988.549304789914,
11936.809166559078,
29174.0,
80.0,
9819.0,
12288.38751553975,
32800.612484460245,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
14803.0,
80.0
],
[
1313.0,
38.273377724105075,
16169.678613767048,
16018.678613767048,
16094.984348740729,
15993.150611305271,
16179.2344346958,
16143.0,
15881.218315763084,
16224.101161390707,
15879.928998044656,
16163.928998044656,
16149.406979950478,
15969.001437722432,
1496.1673310067515,
173.5642302857259,
14816.372854097404,
16264.613347533348,
16095.38531483942,
16172.868212715919,
15933.053835258492,
16184.771515080936,
15962.624692912854,
16319.089687874572,
15952.173123837105,
16444.9718662832,
15997.758097358257,
15989.0,
1313.0,
60.0,
60.0,
14383.0,
16032.38751553975,
16181.61248446025,
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN"
]
]
}
16 changes: 16 additions & 0 deletions test/rest/28.0.0/get/rest/flows/dscp/summaries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"start": 1607940795998,
"end": 1607955195998,
"headers": [
"DSCP",
"Bytes In",
"Bytes Out"
],
"rows": [
[
"0",
739522,
436050
]
]
}
5 changes: 5 additions & 0 deletions test/rest/28.0.0/get/rest/flows/ecn/enumerate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
0,
1,
2
]
32 changes: 32 additions & 0 deletions test/rest/MockHTTP28.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {AbstractMockHTTP} from './AbstractMockHTTP';
import {OnmsHTTPOptions} from '../../src/api/OnmsHTTPOptions';

/** Mock OpenNMS 28.x HTTP implementation */
export class MockHTTP28 extends AbstractMockHTTP {
/** @inheritdoc */
public onGet(url: string, options?: OnmsHTTPOptions) {
switch(url) {
case 'http://demo.opennms.org/opennms/rest/info': {
return this.okJson({
displayVersion: '29.0.0',
packageDescription: 'OpenNMS',
packageName: 'opennms',
version: '29.0.0',
});
}
// Use the v28 responses
case 'rest/flows/dscp': {
return this.okJsonFile('./28.0.0/get/rest/flows/dscp/summaries.json');
}
case 'rest/flows/dscp/enumerate': {
return this.okJsonFile('./28.0.0/get/rest/flows/dscp/enumerate.json');
}
case 'rest/flows/dscp/series': {
return this.okJsonFile('./28.0.0/get/rest/flows/dscp/series.json');
}
case 'rest/flows/ecn/enumerate': {
return this.okJsonFile('./28.0.0/get/rest/flows/ecn/enumerate.json');
}
}
}
}

0 comments on commit 0aa74c9

Please sign in to comment.