This document provides detailed information about all available API methods in the TNSR API Client.
Returns a list of all network interfaces with their configuration and status.
Returns: ApiResponse<InterfaceInfo[]>
Example:
const interfaces = await tnsrClient.listInterfaces();
console.log(JSON.stringify(interfaces, null, 2));Tests the connection to the TNSR API server.
Returns: ApiResponse<{ status: number; message: string }>
Example:
const connectionTest = await tnsrClient.testConnection();
if (connectionTest.success) {
console.log('TNSR API connection successful');
}Returns a list of all configured networks/subnets.
Returns: ApiResponse<NetworkInfo[]>
Example:
const networks = await tnsrClient.listNetworks();
if (networks.success) {
networks.data.forEach(network => {
console.log(`Network: ${network.network}`);
console.log(`Interface: ${network.interface}`);
console.log(`Prefix Length: ${network.prefixLength}`);
});
}Adds a new Policy-Based Route.
Parameters:
ip: string- IP address to routenextHop: string- Next hop IP addresspolicyName: string- Policy name for the routesequence: number- Sequence number for the rule
Returns: ApiResponse<{ policyName: string; sequence: number; routeMapCreated: boolean }>
Example:
const addResult = await tnsrClient.addPbrRoute(
'203.0.113.10', // IP address
'192.168.1.1', // Next hop
'MY-PBR-POLICY', // Policy name
4001 // Sequence
);Removes a Policy-Based Route by policy name.
Parameters:
policyName: string- Name of the policy to remove
Returns: ApiResponse<{ policyName: string; routeMapRemoved: boolean }>
Example:
const removeResult = await tnsrClient.removePbrRoute('MY-PBR-POLICY');Returns a list of all configured PBR routes.
Returns: ApiResponse<PbrRouteInfo[]>
Example:
const pbrRoutes = await tnsrClient.listPbrRoutes();Adds a new blackhole route to drop traffic to specified IP.
Parameters:
ip: string- IP address to blackholerouteTableName: string- Route table name (default: 'default')
Returns: ApiResponse<{ ip: string; routeTableName: string }>
Example:
const addBlackhole = await tnsrClient.addBlackholeRoute(
'192.168.100.50', // IP address
'default' // Route table
);Removes a blackhole route.
Parameters:
ip: string- IP address to remove from blackholerouteTableName: string- Route table name (default: 'default')
Returns: ApiResponse<{ ip: string; routeTableName: string }>
Returns a list of blackhole routes in the specified prefix list.
Parameters:
prefixListName: string- Prefix list name (default: 'DGN-OUT-666')
Returns: ApiResponse<BlackholeRouteInfo[]>
Creates a new route map.
Parameters:
routeMapName: string- Name of the route mapprefixListName: string- Associated prefix list namenextHop: string- Next hop IP addresssequence: number- Sequence number (default: 10)description?: string- Optional description
Returns: ApiResponse<{ routeMapName: string; sequence: number }>
Removes a route map by name.
Parameters:
routeMapName: string- Name of the route map to remove
Returns: ApiResponse<{ routeMapName: string }>
Returns a list of all configured route maps.
Returns: ApiResponse<RouteMapInfo[]>
All API methods return responses in the following format:
interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
message?: string;
metadata?: any; // Additional information (for traffic statistics)
}When an API call fails, the response will have:
success: falseerror: string- Error detailsmessage?: string- Optional error message with suggestions
Example error handling:
const result = await tnsrClient.addPbrRoute('192.168.1.1', '192.168.1.254', 'TEST', 1001);
if (!result.success) {
console.error('Failed to add PBR route:', result.error);
if (result.message) {
console.log('Suggestion:', result.message);
}
}