1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

137 lines
3.1 KiB
React
Raw Normal View History

2018-08-02 14:52:53 +02:00
/*
* Routes Rendering Columns
*/
2018-09-07 14:53:50 +02:00
import _ from 'underscore'
window._ = _;
2018-08-02 14:52:53 +02:00
import React from 'react'
import FilterReason
from 'components/routeservers/large-communities/filter-reason'
import NoexportReason
from 'components/routeservers/large-communities/noexport-reason'
import {ROUTES_RECEIVED,
ROUTES_FILTERED,
ROUTES_NOT_EXPORTED} from './actions';
2018-08-02 14:52:53 +02:00
// Helper:
export const PrimaryIndicator = function(props) {
if (props.route.primary) {
2018-08-02 14:52:53 +02:00
return(
2018-09-07 16:57:16 +02:00
<span className="route-prefix-flag primary-route is-primary-route"><i className="fa fa-star"></i>
2018-08-02 14:52:53 +02:00
<div>Best Route</div>
</span>
);
}
// Default
return (
2018-09-07 14:53:50 +02:00
<span className="route-prefix-flag primary-route not-primary-route"></span>
);
}
export const BlackholeIndicator = function(props) {
// Check if BGP community 65535:666 is set
const communities = props.route.bgp.communities;
let isBlackhole = false;
for (let c of communities) {
if (c[0] == 65535 && c[1] == 666) {
isBlackhole = true;
break;
}
}
if (isBlackhole) {
return(
2018-09-07 16:57:16 +02:00
<span className="route-prefix-flag blackhole-route is-blackhole-route"><i className="fa fa-circle"></i>
<div>Blackhole</div>
2018-09-07 14:53:50 +02:00
</span>
);
}
return (
<span className="route-prefix-flag blackhole-route not-blackhole-route"></span>
);
2018-08-02 14:52:53 +02:00
}
// Helper: Lookup value in route path
export const _lookup = (r, path) => {
return path.split(".").reduce((acc, elem) => acc[elem], r);
}
2018-08-02 14:52:53 +02:00
export const ColDefault = function(props) {
return (
<td>
<span onClick={props.onClick}>{_lookup(props.route, props.column)}</span>
</td>
);
2018-08-02 14:52:53 +02:00
}
// Include filter and noexport reason in this column.
export const ColNetwork = function(props) {
return (
<td className="col-route-network">
<span className="route-network" onClick={props.onClick}>
{props.route.network}
2018-09-07 16:57:16 +02:00
2018-08-02 14:52:53 +02:00
</span>
{props.displayReasons == ROUTES_FILTERED && <FilterReason route={props.route} />}
{props.displayReasons == ROUTES_NOT_EXPORTED && <NoexportReason route={props.route} />}
</td>
);
}
// Special AS Path Widget
export const ColAsPath = function(props) {
const asns = _lookup(props.route, "bgp.as_path");
const baseUrl = "http://irrexplorer.nlnog.net/search/"
let asnLinks = asns.map((asn, i) => {
return (<a key={`${asn}_${i}`} href={baseUrl + asn} target="_blank">{asn} </a>);
});
return (
<td>
{asnLinks}
</td>
);
}
2018-09-07 16:57:16 +02:00
export const ColFlags = function(props) {
return (
<td className="col-route-flags">
<span className="route-prefix-flags">
<PrimaryIndicator route={props.route} />
<BlackholeIndicator route={props.route} />
</span>
</td>
);
}
2018-08-02 14:52:53 +02:00
// Meta component, decides what to render based on on
// prop 'column'.
export default function(props) {
2018-08-02 14:52:53 +02:00
const widgets = {
"network": ColNetwork,
2018-09-07 16:57:16 +02:00
"flags": ColFlags,
2018-08-02 14:52:53 +02:00
"bgp.as_path": ColAsPath,
"ASPath": ColAsPath,
};
let Widget = widgets[props.column] || ColDefault;
return (
<Widget column={props.column} route={props.route}
displayReasons={props.displayReasons}
onClick={props.onClick} />
);
}