#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.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); }
#define XX_MAX_STRING_LENGTH 256
#define XX_PROTO_MAX 10
uint32_t *interface)
{
uint32_t intf = 0;
if (!clientHandle || !interface)
{
}
{
}
{
*interface = intf;
}
return result;
}
{
uint32_t i;
uint32_t protoId = 0;
uint32_t nextProtoId = 0;
for (i = 0; i < XX_PROTO_MAX; i++)
{
if (result ==
OPEN_E_NONE && (strlen(protoName->
pstart)>0)) {
break; }
protoId = nextProtoId;
}
return result;
}
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapRfc1583CompatibilitySet");
}
{
PRINTBADRESULT(result, "openapiOspfMapRfc1583CompatibilityGet");
}
PRINTSANITYRESULTS(result, mode==tmp, __func__);
return;
}
uint32_t duration,
bool override,
uint32_t metric)
{
uint32_t tmpMode;
uint32_t tmpDuration;
uint32_t tmpMetric;
bool tmpOverride;
bool test;
{
mode,
duration);
PRINTBADRESULT(result, "openapiOspfMapStubRtrModeSet");
}
{
override,
metric);
PRINTBADRESULT(result, "openapiOspfMapStubRtrSumLsaMetricOverride");
}
{
&tmpMode,
&tmpDuration,
&tmpOverride,
&tmpMetric);
PRINTBADRESULT(result, "openapiOspfMapStubRtrModeGet");
}
test = tmpMode==mode &&
tmpDuration==duration &&
tmpOverride==override &&
tmpMetric==metric;
PRINTSANITYRESULTS(result, test, __func__);
return;
}
uint32_t autoCost)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapAutoCostRefBwSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapAutoCostRefBwGet");
}
PRINTSANITYRESULTS(result, autoCost==tmp, __func__);
return;
}
char *routerId)
{
uint32_t tmp;
memset(&ipAddr, 0, sizeof(ipAddr));
if (inet_pton(AF_INET, routerId, (
void*)&(ipAddr.
addr.
ipv4)) > 0)
{
ipAddr.addr.ipv4 = ntohl(ipAddr.addr.ipv4);
}
else
{
printf("Bad return code trying to convert ip address.\n");
}
{
PRINTBADRESULT(result, "openapiOspfMapRouterIdSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapRouterIdGet");
}
PRINTSANITYRESULTS(result, ipAddr.addr.ipv4==tmp, __func__);
return;
}
char *area,
{
uint32_t areaId;
if (inet_pton(AF_INET, area, &areaId) != 1)
{
printf("Bad return code trying to convert area id.\n");
}
{
PRINTBADRESULT(result, "openapiOspfMapImportAsExternSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapImportAsExternGet");
}
PRINTSANITYRESULTS(result, import==tmp, __func__);
return;
}
char *area,
{
uint32_t areaId;
if (inet_pton(AF_INET, area, &areaId) != 1)
{
printf("Bad return code trying to convert area id.\n");
}
{
PRINTBADRESULT(result, "openapiOspfMapAreaSummarySet");
}
{
PRINTBADRESULT(result, "openapiOspfMapAreaSummaryGet");
}
PRINTSANITYRESULTS(result, summary==tmp, __func__);
return;
}
uint32_t extPref,
uint32_t intPref,
uint32_t locPref)
{
uint32_t tmp;
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet INTRA");
{
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet INTRA");
}
PRINTSANITYRESULTS(result, intPref==tmp, __func__);
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet EXTERNAL");
{
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet EXTERNAL");
}
PRINTSANITYRESULTS(result, extPref==tmp, __func__);
PRINTBADRESULT(result, "openapiIpRouterPreferenceSet Local INTER");
{
PRINTBADRESULT(result, "openapiIpRouterPreferenceGet Local INTER");
}
PRINTSANITYRESULTS(result, locPref==tmp, __func__);
return;
}
uint32_t intf,
char *area,
{
uint32_t areaId;
uint32_t tmpArea;
if (inet_pton(AF_INET, area, &areaId) != 1)
{
printf("Bad return code trying to convert area id.\n");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfAreaIdSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfAreaIdGet");
}
PRINTSANITYRESULTS(result, (areaId==tmpArea&&mode==tmpMode), __func__);
return;
}
uint32_t intf,
char *ipAddr,
uint32_t metric)
{
uint32_t tmpAddr;
uint32_t tmp;
if (inet_pton(AF_INET, ipAddr, &tmpAddr) != 1)
{
tmpAddr = atoi(ipAddr);
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfMetricValueSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfMetricValueGet");
}
PRINTSANITYRESULTS(result, metric==tmp, __func__);
return;
}
uint32_t intf,
uint32_t seconds)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapIntfDeadIntervalSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfDeadIntervalGet");
}
PRINTSANITYRESULTS(result, seconds==tmp, __func__);
return;
}
uint32_t intf,
uint32_t seconds)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapIntfHelloIntervalSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfHelloIntervalGet");
}
PRINTSANITYRESULTS(result, seconds==tmp, __func__);
return;
}
uint32_t intf,
{
{
PRINTBADRESULT(result, "openapiOspfMapIntfTypeSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfTypeGet");
}
PRINTSANITYRESULTS(result, type==tmp, __func__);
return;
}
uint32_t intf,
uint32_t secondaries)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapIntfSecondariesFlagSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfSecondariesFlagGet");
}
PRINTSANITYRESULTS(result, (secondaries==tmp), __func__);
return;
}
bool detail)
{
bool tmpDetail;
{
PRINTBADRESULT(result, "openapiOspfMapLogAdjChngSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapLogAdjChngGet");
}
PRINTSANITYRESULTS(result, (log==tmpLog && detail==tmpDetail), __func__);
return;
}
{
uint32_t maxPaths;
uint32_t tmpPaths;
{
PRINTBADRESULT(result, "openapiOspfMapMaxPathsSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapMaxPathsGet");
}
PRINTSANITYRESULTS(result, (maxPaths==tmpPaths), __func__);
return;
}
char *ipAddr,
char *mask,
uint32_t areaId,
bool create)
{
uint32_t tmpAddr;
uint32_t tmpMask;
bool tmp = true;
if (inet_pton(AF_INET, ipAddr, &tmpAddr) != 1)
{
tmpAddr = atoi(ipAddr);
}
if (inet_pton(AF_INET, mask, &tmpMask) != 1)
{
tmpMask = atoi(mask);
}
if (create)
{
{
PRINTBADRESULT(result, "openapiOspfMapNetworkAreaEntrySet");
}
{
PRINTBADRESULT(result, "openapiOspfMapNetworkAreaEntryGet");
}
}
else
{
PRINTBADRESULT(result, "openapiOspfMapNetworkAreaEntryDelete");
}
PRINTSANITYRESULTS(result, tmp, __func__);
return;
}
uint32_t intf,
bool mode)
{
bool tmp;
{
PRINTBADRESULT(result, "openapiOspfMapIntfPassiveModeSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapIntfPassiveModeGet");
}
PRINTSANITYRESULTS(result, mode==tmp, __func__);
return;
}
bool redistribute,
uint32_t distList,
uint32_t metric,
uint32_t type,
int32_t tag,
bool subnets)
{
protoName.size++;
protoName.pstart = malloc(protoName.size);
result = getFirstRoutingProtocolName(clientHandle, &protoName);
{
redistribute,
&protoName,
distList,
metric,
type,
tag,
subnets);
}
PRINTBADRESULT(result, "openapiOspfMapRedistributionSet");
PRINTSANITYRESULTS(result, 1==1, __func__);
free(protoName.pstart);
return;
}
uint32_t time)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapSpfDelayTimeSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapSpfDelayTimeGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
uint32_t time)
{
uint32_t tmp;
{
PRINTBADRESULT(result, "openapiOspfMapSpfHoldTimeSet");
}
{
PRINTBADRESULT(result, "openapiOspfMapSpfHoldTimeGet");
}
PRINTSANITYRESULTS(result, time==tmp, __func__);
return;
}
bool mode)
{
bool tmp;
{
PRINTBADRESULT(result, "openapiOspfTrapModeSet");
}
{
PRINTBADRESULT(result, "openapiOspfTrapModeGet");
}
PRINTSANITYRESULTS(result, mode==tmp, __func__);
return;
}
int main (int argc, char **argv)
{
uint32_t source = 0;
l7proc_crashlog_register();
if ((result =
{
printf ("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
exit (2);
}
{
sleep (1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Starting OSPF API example application");
printf ("\n");
printf ("Begin Sanity tests...\n");
printf ("\nEstablish OSPF and global parameters...\n");
testRouterId(&clientHandle, "9.0.0.3");
testAutoCost(&clientHandle, 4294967);
testSPFDelayTime(&clientHandle, 65535);
testSPFHoldTime(&clientHandle, 65535);
testDistance(&clientHandle, 10, 20, 30);
testMaxPaths(&clientHandle);
testTrapFlags(&clientHandle, trapFlags, true);
testTrapFlags(&clientHandle, trapFlags, false);
if (getFirstRoutingInterface(&clientHandle, &source) ==
OPEN_E_NONE)
{
printf ("Configure IP area with miscellaneous interface related parameters...\n");
testIPArea(&clientHandle, source,
"0.0.0.0",
OPEN_ENABLE);
testIPDeadInterval(&clientHandle, source, 65535);
testIPHelloInterval(&clientHandle, source, 65535);
testPassive(&clientHandle, 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");
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Stopping OSPF API example application");
return 0;
}