Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.6.0.3
bgp_example.c
/*********************************************************************
*
* Copyright 2016-2018 Broadcom.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************
*
* @filename bgp_example.c
*
* @purpose BGP APIs Example.
*
* @component OPEN
*
* @note
*
* @create 04/23/2013
*
* @end
*
**********************************************************************/
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#include "openapi_common.h"
#define PRINTSANITYRESULTS(result, test, msg) \
if ((result==OPEN_E_NONE) && (test)) { printf("Sanity Success - %s\n", msg); } \
else { printf("Sanity Failure - %s\n", msg); }
#define PRINTBADRESULT(result, msg) \
if (result!=OPEN_E_NONE) { printf("Test Failure - %s (err %d)\n", msg, result); }
/* Maximum string length to be used for inputs */
#define XX_MAX_STRING_LENGTH 256
/* Maximum number of protocol names */
#define XX_PROTO_MAX 10
/*****************************************************************/
open_error_t getFirstRoutingInterface(openapiClientHandle_t *clientHandle,
uint32_t *interface)
{
uint32_t intf = 0;
if (!clientHandle || !interface)
{
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiRtrIntfNextGet(clientHandle, intf, &intf);
}
if (result == OPEN_E_NONE)
{
*interface = intf;
}
return result;
}
/*****************************************************************/
open_error_t getFirstRoutingProtocolName(openapiClientHandle_t *clientHandle,
open_buffdesc *protoName)
{
uint32_t i;
uint32_t protoId = 0;
uint32_t nextProtoId = 0;
for (i = 0; i < XX_PROTO_MAX; i++)
{
result = openapiIpRouterProtoNameNextGet(clientHandle, protoId, protoName, &nextProtoId);
/* Get the first available protocol name */
if (result == OPEN_E_NONE && (strlen(protoName->pstart)>0)) { break; }
protoId = nextProtoId;
}
return result;
}
/*****************************************************************/
void testLocalAS(openapiClientHandle_t *clientHandle,
uint32_t asn)
{
uint32_t tmp;
result = openapiBgpLocalASSet (clientHandle, asn);
PRINTBADRESULT(result, "openapiBgpLocalASSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpLocalASGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpLocalASGet");
}
PRINTSANITYRESULTS(result, asn==tmp, __func__);
return;
}
/*****************************************************************/
void testGlobalHoldTime(openapiClientHandle_t *clientHandle,
uint32_t time)
{
uint32_t tmp;
result = openapiBgpGlobalHoldTimeConfiguredSet (clientHandle, time);
PRINTBADRESULT(result, "openapiBgpGlobalHoldTimeConfiguredSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpGlobalHoldTimeConfiguredGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpGlobalHoldTimeConfiguredGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
/*****************************************************************/
void testGlobalKeepAlive(openapiClientHandle_t *clientHandle,
uint32_t time)
{
uint32_t tmp;
result = openapiBgpGlobalKeepAliveConfiguredSet (clientHandle, time);
PRINTBADRESULT(result, "openapiBgpGlobalKeepAliveConfiguredSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpGlobalKeepAliveConfiguredGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpGlobalKeepAliveConfiguredGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
/*****************************************************************/
void testLocalId(openapiClientHandle_t *clientHandle,
char *routerId)
{
uint32_t tmp;
memset(&ipAddr, 0, sizeof(ipAddr));
if (inet_pton(AF_INET, routerId, (void*)&(ipAddr.addr.ipv4)) > 0)
{
ipAddr.family = OPEN_AF_INET;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpLocalIdSet (clientHandle, ipAddr.addr.ipv4);
PRINTBADRESULT(result, "openapiBgpLocalIdSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpLocalIdGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpLocalIdGet");
}
PRINTSANITYRESULTS(result, ipAddr.addr.ipv4==tmp, __func__);
return;
}
/*****************************************************************/
void testLocalPref(openapiClientHandle_t *clientHandle,
uint32_t pref)
{
uint32_t tmp;
result = openapiBgpLocalPrefSet (clientHandle, pref);
PRINTBADRESULT(result, "openapiBgpLocalPrefSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpLocalPrefGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpLocalPrefGet");
}
PRINTSANITYRESULTS(result, pref==tmp, __func__);
return;
}
/*****************************************************************/
void testDistance(openapiClientHandle_t *clientHandle,
uint32_t extPref,
uint32_t intPref,
uint32_t locPref)
{
uint32_t tmp;
/* Internal test */
result = openapiIpRouterPreferenceSet (clientHandle, OPEN_PREF_IBGP, intPref);
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet IBGP");
if (result == OPEN_E_NONE)
{
result = openapiIpRouterPreferenceGet (clientHandle, OPEN_PREF_IBGP, &tmp);
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet IBGP");
}
PRINTSANITYRESULTS(result, intPref==tmp, __func__);
/* External test */
result = openapiIpRouterPreferenceSet (clientHandle, OPEN_PREF_EBGP, extPref);
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet EBGP");
if (result == OPEN_E_NONE)
{
result = openapiIpRouterPreferenceGet (clientHandle, OPEN_PREF_EBGP, &tmp);
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet EBGP");
}
PRINTSANITYRESULTS(result, extPref==tmp, __func__);
/* Local test */
result = openapiIpRouterPreferenceSet (clientHandle, OPEN_PREF_LOCAL_BGP, locPref);
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet Local BGP");
if (result == OPEN_E_NONE)
{
result = openapiIpRouterPreferenceGet (clientHandle, OPEN_PREF_LOCAL_BGP, &tmp);
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet Local BGP");
}
PRINTSANITYRESULTS(result, locPref==tmp, __func__);
return;
}
/*****************************************************************/
void testLogNeighbor(openapiClientHandle_t *clientHandle,
bool log)
{
bool tmp;
result = openapiBgpLogNeighborChangesSet (clientHandle, log);
PRINTBADRESULT(result, "openapiBgpLogNeighborChangesSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpLogNeighborChangesGet (clientHandle, &tmp);
PRINTBADRESULT(result, "openapiBgpLogNeighborChangesGet");
}
PRINTSANITYRESULTS(result, log==tmp, __func__);
return;
}
/*****************************************************************/
void testMaxPaths(openapiClientHandle_t *clientHandle,
bool isIbgp)
{
uint32_t maxPaths;
uint32_t tmpPaths;
/* Get max # of paths for the active template */
result = openapiBgpMaxPathsGet(clientHandle, af, isIbgp, &maxPaths);
result = openapiBgpMaxPathsSet(clientHandle, af, isIbgp, maxPaths);
PRINTBADRESULT(result, "openapiBgpMaxPathsSet");
if (result == OPEN_E_NONE)
{
result = openapiBgpMaxPathsGet(clientHandle, af, isIbgp, &tmpPaths);
PRINTBADRESULT(result, "openapiBgpMaxPathsGet");
}
PRINTSANITYRESULTS(result, maxPaths==tmpPaths, __func__);
return;
}
/*****************************************************************/
void testNetwork(openapiClientHandle_t *clientHandle,
bool normalMode,
bool useRm,
char *ipStr,
uint32_t pfxLen,
char *rmNameStr)
{
char str[XX_MAX_STRING_LENGTH];
open_buffdesc rmName;
memset(&ipAddr, 0, sizeof(ipAddr));
if (inet_pton(AF_INET, ipStr, (void*)&(ipAddr.addr.ipv4)) > 0)
{
ipAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, ipStr, (void*)&(ipAddr.addr.ipv6)) > 0)
{
ipAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
strcpy(str, rmNameStr);
rmName.pstart = str;
rmName.size = strlen(str)+1;
result = openapiBgpNetworkAddDelete (clientHandle,
normalMode,
useRm,
ipAddr,
pfxLen,
&rmName);
PRINTBADRESULT(result, "openapiBgpNetworkAddDelete");
PRINTSANITYRESULTS(result, 1==1, __func__);
}
return;
}
/*****************************************************************/
void testRedistribution(openapiClientHandle_t *clientHandle,
bool add,
bool matchSet,
uint32_t matchBits,
bool metricSet,
bool metricValueSet,
uint32_t metricValue,
bool routeMapSet,
char *rmNameStr)
{
char str[XX_MAX_STRING_LENGTH];
open_buffdesc rmName;
open_buffdesc protoName;
open_error_t result;
strcpy(str, rmNameStr);
rmName.pstart = str;
rmName.size = strlen(str);
openapiRouteProtoNameLenMax(clientHandle, &protoName.size);
protoName.size++; /* leave room for NULL terminator */
protoName.pstart = malloc(protoName.size);
result = getFirstRoutingProtocolName(clientHandle, &protoName);
if (result == OPEN_E_NONE)
{
result = openapiBgpRedistributionSet(clientHandle,
add,
&protoName,
matchSet,
matchBits,
metricSet,
metricValueSet,
metricValue,
routeMapSet,
af,
&rmName);
}
PRINTBADRESULT(result, "openapiBgpRedistributionSet");
PRINTSANITYRESULTS(result, 1==1, __func__);
free(protoName.pstart);
return;
}
/*****************************************************************/
void testPeerActivate(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
bool activate,
bool defValue)
{
open_inet_addr_t remoteAddr;
bool tmp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerActivateSet(clientHandle,
remoteAddr,
scopeId,
af,
activate,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerActivateSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerActivateGet(clientHandle,
remoteAddr,
scopeId,
af,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerActivateGet");
}
PRINTSANITYRESULTS(result, activate==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerAdminStatus(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
bool defValue)
{
open_inet_addr_t remoteAddr;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerAdminStatusSet(clientHandle,
remoteAddr,
scopeId,
status,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerAdminStatusSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerAdminStatusGet(clientHandle,
remoteAddr,
scopeId,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerAdminStatusGet");
}
PRINTSANITYRESULTS(result, status==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerAdvertisement(openapiClientHandle_t *clientHandle,
OPEN_AF_t af,
char *peerIpStr,
uint32_t scopeId,
uint32_t interval,
bool defValue)
{
open_inet_addr_t remoteAddr;
uint32_t tmp;
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
remoteAddr,
scopeId,
af,
interval,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerAdvertisementIntervalSet");
}
if (result == OPEN_E_NONE)
{
remoteAddr,
scopeId,
af,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerAdvertisementIntervalGet");
}
PRINTSANITYRESULTS(result, interval==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerHoldTime(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
uint32_t time,
bool defValue)
{
open_inet_addr_t remoteAddr;
uint32_t tmp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerHoldTimeConfiguredSet(clientHandle,
remoteAddr,
scopeId,
time,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerHoldTimeConfiguredSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerHoldTimeConfiguredGet(clientHandle,
remoteAddr,
scopeId,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerHoldTimeConfiguredGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerKeepAlive(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
uint32_t time,
bool defValue)
{
open_inet_addr_t remoteAddr;
uint32_t tmp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerKeepAliveConfiguredSet(clientHandle,
remoteAddr,
scopeId,
time,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerKeepAliveConfiguredSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerKeepAliveConfiguredGet(clientHandle,
remoteAddr,
scopeId,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerKeepAliveConfiguredGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerRemoteAS(openapiClientHandle_t *clientHandle,
uint32_t asn,
char *peerIpStr,
uint32_t scopeId)
{
open_inet_addr_t remoteAddr;
uint32_t tmp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerRemoteASSet(clientHandle,
remoteAddr,
scopeId,
asn);
PRINTBADRESULT(result, "openapiBgpPeerRemoteASSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerRemoteASGet(clientHandle,
remoteAddr,
scopeId,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerRemoteASGet");
}
PRINTSANITYRESULTS(result, asn==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerNextHopSelf(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
bool defValue)
{
open_inet_addr_t remoteAddr;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerNextHopSelfModeSet(clientHandle,
remoteAddr,
scopeId,
af,
enable,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerNextHopSelfModeSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerNextHopSelfModeGet(clientHandle,
remoteAddr,
scopeId,
af,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerNextHopSelfModeGet");
}
PRINTSANITYRESULTS(result, enable==tmp, __func__);
return;
}
/*****************************************************************/
void testPeerPfxLimit(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
uint32_t threshold,
bool warningOnly,
bool defValue)
{
open_inet_addr_t remoteAddr;
uint32_t pfxLimit;
uint32_t pTemp;
uint32_t tTemp;
bool bTemp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
/* Demonstrate get/set the maximum number of IPv4 routes */
result = openapiBgpIpv4RouteMax(clientHandle, &pfxLimit);
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
/* Demonstrate alternate method to use the maximum number routes */
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerPfxLimitSet(clientHandle,
remoteAddr,
scopeId,
af,
pfxLimit,
threshold,
warningOnly,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerPfxLimitSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerPfxLimitGet(clientHandle,
remoteAddr,
scopeId,
af,
&pTemp,
&tTemp,
&bTemp);
PRINTBADRESULT(result, "openapiBgpPeerPfxLimitGet");
}
PRINTSANITYRESULTS(result, (pfxLimit==pTemp && threshold==tTemp && warningOnly==bTemp), __func__);
return;
}
/*****************************************************************/
void testPeerUpdateSource(openapiClientHandle_t *clientHandle,
char *peerIpStr,
uint32_t scopeId,
uint32_t source,
bool defValue)
{
open_inet_addr_t remoteAddr;
uint32_t tmp;
memset(&remoteAddr, 0, sizeof(remoteAddr));
if (inet_pton(AF_INET, peerIpStr, (void*)&(remoteAddr.addr.ipv4)) > 0)
{
remoteAddr.family = OPEN_AF_INET;
}
else if (inet_pton(AF_INET6, peerIpStr, (void*)&(remoteAddr.addr.ipv6)) > 0)
{
remoteAddr.family = OPEN_AF_INET6;
}
else
{
printf("Bad return code trying to convert ip address.\n");
result = OPEN_E_PARAM;
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerUpdateSourceSet(clientHandle,
remoteAddr,
scopeId,
source,
defValue);
PRINTBADRESULT(result, "openapiBgpPeerUpdateSourceSet");
}
if (result == OPEN_E_NONE)
{
result = openapiBgpPeerUpdateSourceGet(clientHandle,
remoteAddr,
scopeId,
&tmp);
PRINTBADRESULT(result, "openapiBgpPeerUpdateSourceGet");
}
PRINTSANITYRESULTS(result, source==tmp, __func__);
return;
}
/***************************************************************/
int main (int argc, char **argv)
{
openapiClientHandle_t clientHandle;
open_error_t result;
OPEN_OSPF_METRIC_TYPES_t matchBits = 0;
uint32_t source = 0;
l7proc_crashlog_register();
/* Register with OpEN */
if ((result =
openapiClientRegister ("bgp_example", &clientHandle)) != OPEN_E_NONE)
{
printf ("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
exit (2);
}
/* RPC call can fail until server starts. Keep trying */
while (openapiConnectivityCheck (&clientHandle) != OPEN_E_NONE)
{
sleep (1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Starting BGP API example application");
printf ("\n");
/* Execute sanity tests */
printf ("Begin Sanity tests...\n");
/**************************************************************************/
/* Global BGP specific tests */
/**************************************************************************/
printf ("Establish BGP and global parameters...\n");
testLocalAS(&clientHandle, 1);
testLocalId(&clientHandle, "1.1.1.1");
testLocalPref(&clientHandle, 1234567890);
testDistance(&clientHandle, 10, 20, 30);
testGlobalHoldTime(&clientHandle, 65535);
testGlobalKeepAlive(&clientHandle, 65535);
testLogNeighbor(&clientHandle, true);
testMaxPaths(&clientHandle, OPEN_AF_INET, false);
testMaxPaths(&clientHandle, OPEN_AF_INET, true);
testNetwork(&clientHandle, true, true, "20.10.0.0", 24, "my-map1");
testNetwork(&clientHandle, false, true, "20.10.0.0", 24, "my-map1");
/* Demonstrate internal, external, and NSSA external bit sets */
testRedistribution(&clientHandle, true, true, matchBits, true, true,
4294967295UL, false, OPEN_AF_INET, "");
/**************************************************************************/
/* Neighbor specific tests */
/**************************************************************************/
printf ("Create a ipv4 test peer...\n");
testPeerRemoteAS(&clientHandle, 1, "2.2.2.2", 0);
testPeerAdminStatus(&clientHandle, "2.2.2.2", 0, OPEN_BGP_START, true);
testPeerKeepAlive(&clientHandle, "2.2.2.2", 0, 600, true);
testPeerHoldTime(&clientHandle, "2.2.2.2", 0, 700, true);
testPeerActivate(&clientHandle, OPEN_AF_INET6, "2.2.2.2", 0, true, true);
testPeerAdvertisement(&clientHandle, OPEN_AF_INET, "2.2.2.2", 0, 200, true);
testPeerNextHopSelf(&clientHandle, OPEN_AF_INET, "2.2.2.2", 0, OPEN_ENABLE, true);
testPeerPfxLimit(&clientHandle, OPEN_AF_INET, "2.2.2.2", 0, 20, true, true);
printf ("Create a ipv6 test peer...\n");
testPeerRemoteAS(&clientHandle, 1, "2222::", 0);
testPeerAdminStatus(&clientHandle, "2222::", 0, OPEN_BGP_STOP, true);
testPeerKeepAlive(&clientHandle, "2222::", 0, 600, true);
testPeerHoldTime(&clientHandle, "2222::", 0, 700, true);
testPeerActivate(&clientHandle, OPEN_AF_INET6, "2222::", 0, true, true);
testPeerAdvertisement(&clientHandle, OPEN_AF_INET6, "2222::", 0, 222, true);
testPeerNextHopSelf(&clientHandle, OPEN_AF_INET6, "2222::", 0, OPEN_ENABLE, true);
testPeerPfxLimit(&clientHandle, OPEN_AF_INET6, "2222::", 0, 60, true, true);
/* Test to see if we have a routing interface */
if (getFirstRoutingInterface(&clientHandle, &source) == OPEN_E_NONE)
{
/* Assign this link local address to our routing interface */
testPeerRemoteAS(&clientHandle, 1, "fe80::1", source);
/* Use same routing interface, simply for demonstration */
testPeerUpdateSource(&clientHandle, "2.2.2.2", 0, source, true);
}
else
{
printf ("Sanity tests are incomplete because no routing interfaces are available!\n");
printf ("Please configure a routing interface and re-run test.\n\n");
}
printf ("Complete.\n");
/* Log goodbye message with OPEN */
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Stopping BGP API example application");
(void) openapiClientTearDown(&clientHandle);
return 0;
}