/* sgend.c : dynamic script generator for MGEN tools * Copyright 1996 Brian Adamson, NEWLINK Global Engineering Corporation. * All Rights Reserved. */ #include #include #include #include #include #include #include /* #include "version.h" */ #define VERSION "2.6a1" #define TRUE 1 #define FALSE 0 #ifndef INADDR_NONE #define INADDR_NONE 0xFFFFFFFF #endif int main(argc, argv) int argc; char *argv[]; { extern char *optarg; extern int optind, opterr; register int op; int nonopt_argc; int numClusters = 1; int groupsPerCluster, j; char tempchar; int tempint; float tempfloat; char baseAddress[128], dottedAddress[128]; struct in_addr ipAddress, theAddress; char fileName[128]; int numGroups = 1; /* at least one destination */ float packetRate = 1.0; /* default packetRate */ int duration = 100000; /* default is non stop test */ int packetSize = 64; /* default packetSize */ int port = 5000; /* default port */ int offset = 0; /* default offset */ long time, startTime = 0; FILE *outFile; int flow_id = 1; /* start with flow_id = 1 */ int i, Multicast; strcpy(baseAddress, "224.0.0.1"); printf("SGEN: Version %s\n", VERSION); /* Parse options */ optind = 1; opterr = 0; while ((op = getopt(argc, argv, "n:c:b:d:o:p:s:v")) != EOF) { switch(op) { case 'n': numGroups = atoi(optarg); break; case 'c': numClusters = atoi(optarg); break; case 'b': strcpy(baseAddress, optarg); break; case 'd': duration = atoi(optarg); /* default is forever */ if (duration < 0) { printf("sgen: Invalid duration!\n"); exit(0); } break; case 'o': offset = atoi(optarg); if (offset < 0) { printf("SGEN: Invalid offset!\n"); exit(0); } break; case 'p': port = atoi(optarg); if (port < 0) { printf("SGEN: Invalid port!\n"); exit(0); } break; case 's': packetSize = atoi(optarg); if ((packetSize < 32) || (packetSize > 1500)) { printf("SGEN: Invalid packetSize!\n"); exit(0); } break; case 'v': exit(0); break; default: printf("SGEN: Invalid command line option!\n"); exit(0); break; } } nonopt_argc = argc - optind; if (nonopt_argc != 1) { printf("Usage: sgend [-b baseAddress] [-n numGroups] [-d duration] [-c nclusters] scriptFile\n"); exit(0); } /* Test for unicast vs. multicast */ if ( (ipAddress.s_addr = inet_addr(baseAddress)) == INADDR_NONE) { printf("sgen: Invalid baseAddress!\n"); exit(0); } if ((ipAddress.s_addr & 0xf0000000) == 0xe0000000) { /* (TBD) Should check for out of bounds address here */ Multicast = TRUE; } else { Multicast = FALSE; } printf("Multicast = %d\n", Multicast); if (Multicast) /* DREC script file needed for multicast only, not unicast */ { strcpy(fileName, argv[optind]); strcat(fileName, ".rec"); if ( ( outFile = fopen(fileName, "w+") ) == NULL) { perror("\nsgen: Error opening scriptFile"); exit(0); } printf("SGEN: Opened output file: %s ...\n", fileName); groupsPerCluster = numGroups/numClusters; time = startTime; theAddress.s_addr = ipAddress.s_addr; printf("SGEN: Writing DREC 'JOIN' events ...\n"); fprintf(outFile, "/* DREC script file generated by SGEN */\n"); j = 0; for (i=0; i