/*
* Routes Rendering Columns
*/
import _ from 'underscore'
window._ = _;
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';
// Helper:
export const PrimaryIndicator = function(props) {
if (props.route.primary) {
return(
Best Route
);
}
// Default
return (
);
}
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(
Blackhole
);
}
return (
);
}
// Helper: Lookup value in route path
export const _lookup = (r, path) => {
return path.split(".").reduce((acc, elem) => acc[elem], r);
}
export const ColDefault = function(props) {
return (
{_lookup(props.route, props.column)}
|
);
}
// Include filter and noexport reason in this column.
export const ColNetwork = function(props) {
return (
{props.route.network}
{props.displayReasons == ROUTES_FILTERED && }
{props.displayReasons == ROUTES_NOT_EXPORTED && }
|
);
}
// 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 ({asn} );
});
return (
{asnLinks}
|
);
}
export const ColFlags = function(props) {
return (
|
);
}
// Meta component, decides what to render based on on
// prop 'column'.
export default function(props) {
const widgets = {
"network": ColNetwork,
"flags": ColFlags,
"bgp.as_path": ColAsPath,
"ASPath": ColAsPath,
};
let Widget = widgets[props.column] || ColDefault;
return (
);
}