📄 itgsend.cpp
字号:
#endif
int j = 0;
int h = 0;
int id = para->flowId;
long int Delay = DefaultDelay;
int chanId;
struct pipeMsg msg;
#ifdef DEBUG
printf("flowParser() started\n");
#endif
flows[id].id = id;
flows[id].meter = METER_OWDM;
flows[id].l7Proto = LX_PROTO_NONE;
flows[id].l4Proto = L4_PROTO_UDP;
flows[id].DSByte = DefaultDSByte;
flows[id].Duration = DefaultDuration;
flows[id].icmptype = 8;
flows[id].TTL = 0;
flows[id].Nagle = true;
flows[id].srcPortSpecify = false;
strcpy(flows[id].serialReceiver,"noSerial");
flows[id].serial = INVALID_HANDLE_VALUE;
if (para->line[strlen(para->line) - 1] == '\n') {
para->line[strlen(para->line) - 1] = '\0';
} else {
cerr << " No newline at the end of file" << endl;
memClean();
exit(1);
}
if (managerMode) {
ManagerMsg = (char *) malloc(sizeof(char) * strlen(para->line) + sizeof(int) * 2);
strcpy(ManagerMsg, para->line);
}
getaddrinfo(DefaultDestIP, NULL, NULL, &flows[id].DestHost);
SET_PORT(flows[id].DestHost, htons(DEFAULT_PORT));
getaddrinfo(DefaultDestIP, NULL, NULL, &flows[id].SrcHost);
if (!multiFlows) {
strcpy(logFile, DefaultLogFile);
getaddrinfo(DefaultDestIP, NULL, NULL, &logHost);
SET_PORT(logHost, htons(DEFAULT_LOG_PORT));
protoTxLog = DEFAULT_PROTOCOL_TX_LOG;
getaddrinfo(DefaultDestIP, NULL, NULL, &serverLogReceiver);
SET_PORT(serverLogReceiver, htons(DEFAULT_LOG_PORT));
protoTx_ServerLogReceiver = DEFAULT_PROTOCOL_TX_LOG_OPZ;
}
flows[id].IntArrivDistro = pdConstant;
ConstantRV = new Constant(1);
flows[id].IntArriv = new SumRandom(1000.0 / DefaultPktPerSec * (*ConstantRV));
flows[id].PktSizeDistro = pdConstant;
ConstantRV = new Constant(1);
flows[id].PktSize = new SumRandom(DefaultPktSize * (*ConstantRV));
token = strtok(para->line, " ");
while (token != NULL) {
argv[j] = token;
j++;
token = strtok(NULL, " ");
}
argc = j;
while (argc > 0) {
if (argv[h][0] == '-') {
char *tail;
long int temp = 0;
Real a, b;
switch (argv[h][1]) {
case 'm':
flows[id].meter = findMeter(argv[h + 1]);
if (flows[id].meter == 255)
ReportErrorAndExit("General parser", "Invalid measure type",
programName, 0);
h += 2;
argc -= 2;
break;
case 'a':
in_port_t tmp_port;
if (flows[id].DestHost) {
GET_PORT(flows[id].DestHost, tmp_port);
freeaddrinfo(flows[id].DestHost);
}
if ((argc < 2) || getaddrinfo(argv[h + 1], NULL, NULL, &flows[id].DestHost))
ReportErrorAndExit("General parser",
"Invalid destination address", programName, id);
SET_PORT(flows[id].DestHost, tmp_port);
h += 2;
argc -= 2;
break;
case 'r':
if (argv[h][2] == 'p') {
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid port number",
programName, id);
SET_PORT(flows[id].DestHost, htons(atoi(argv[h + 1])));
h += 2;
argc -= 2;
}
else if (argv[h][2] == 'k') {
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid Serial Port",
programName, id);
strcpy(flows[id].serialReceiver, argv[h+1]);
#ifdef DEBUG
printf("at Receiver Side %s is up \n", argv[h + 1]);
#endif
h += 2;
argc -= 2;
}
else {
char tempS[sizeof("What is ?") + sizeof(argv[h])];
ReportErrorAndExit("General parser", strcat(strcat(strcpy(tempS,
"What is "), argv[h]), " ?"), programName, id);
}
break;
case 'f':
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid TTL",
programName, id);
temp = strtol(argv[h + 1], &tail, 0);
strcpy(flows[id].serialReceiver,"noSerial");if ((tail == argv[h + 1]) || (temp < 0) || (temp > 255))
ReportErrorAndExit("General parser", "Invalid TTL",
programName, id);
flows[id].TTL = temp;
h += 2;
argc -= 2;
break;
case 't':
if ((argc < 2) || ((temp = strtol(argv[h + 1], NULL, 10)) <= 0))
ReportErrorAndExit("General parser", "Invalid Duration",
programName, id);
flows[id].Duration = temp;
h += 2;
argc -= 2;
break;
case 'd':
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid Delay",
programName, id);
temp = strtol(argv[h + 1], &tail, 10);
if ((tail == argv[h + 1]) || (temp < 0))
ReportErrorAndExit("General parser", "Invalid Delay",
programName, id);
Delay = temp;
h += 2;
argc -= 2;
break;
case 'b':
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid DS Byte",
programName, id);
temp = strtol(argv[h + 1], &tail, 0);
if ((tail == argv[h + 1]) || (temp < 0) || (temp > 255))
ReportErrorAndExit("General parser", "Invalid DS Byte",
programName, id);
flows[id].DSByte = temp;
h += 2;
argc -= 2;
break;
case 'L':
if (multiFlows)
ReportErrorAndExit("General parser",
"-L option not allowed into script file", programName,
id);
logging = 1;
logremoto = 1;
if ((argc < 2) || (argv[h+1][0] == '-') ||
(findL7Proto(argv[h+1]) != LX_ERROR_BYTE)){
argc -= 1;
h += 1;
} else {
if (findL4Proto(argv[h + 1]) == LX_ERROR_BYTE){
if (logHost)
freeaddrinfo(logHost);
if (getaddrinfo(argv[h + 1], NULL, NULL, &logHost))
ReportErrorAndExit("General parser",
" Invalid log-server address or protocol", programName, id);
argc -= 1;
h += 1;
} else {
protoTxLog = findL4Proto(argv[h + 1]);
argc -= 1;
h += 1;
}
if ((argc >= 2) && (argv[h+1][0] != '-') && (findL7Proto(argv[h+1]) == LX_ERROR_BYTE)) {
if (findL4Proto(argv[h + 1]) == LX_ERROR_BYTE){
if (logHost)
freeaddrinfo(logHost);
if (getaddrinfo(argv[h + 1], NULL, NULL, &logHost))
ReportErrorAndExit("General parser",
" Invalid log-server address", programName, id);
argc -= 2;
h += 2;
} else {
protoTxLog = findL4Proto(argv[h + 1]);
argc -= 2;
h += 2;
}
}
else {
argc -= 1;
h += 1;
}
}
break;
case 'X':
if (multiFlows)
ReportErrorAndExit("General parser",
"-X option not allowed into script file", programName,
id);
logServer = 1;
if ((argc < 2) || (argv[h+1][0] == '-') ||
(findL7Proto(argv[h+1]) != LX_ERROR_BYTE)){
argc -= 1;
h += 1;
} else {
if (findL4Proto(argv[h + 1]) == LX_ERROR_BYTE){
if (serverLogReceiver)
freeaddrinfo(serverLogReceiver);
if (getaddrinfo(argv[h + 1], NULL, NULL, &serverLogReceiver))
ReportErrorAndExit("General parser",
" Invalid log-server address or protocol", programName, id);
argc -= 1;
h += 1;
} else {
protoTx_ServerLogReceiver = findL4Proto(argv[h + 1]);
argc -= 1;
h += 1;
}
if ((argc >= 2) && (argv[h+1][0] != '-') && (findL7Proto(argv[h+1]) == LX_ERROR_BYTE)) {
if (findL4Proto(argv[h + 1]) == LX_ERROR_BYTE){
if (serverLogReceiver)
freeaddrinfo(serverLogReceiver);
if (getaddrinfo(argv[h + 1], NULL, NULL, &serverLogReceiver))
ReportErrorAndExit("General parser",
" Invalid log-server address", programName, id);
argc -= 2;
h += 2;
} else {
protoTx_ServerLogReceiver = findL4Proto(argv[h + 1]);
argc -= 2;
h += 2;
}
}
else {
argc -= 1;
h += 1;
}
}
break;
case 'T':
if (argc < 2)
ReportErrorAndExit("General parser",
"Invalid Protocol Type", programName, id);
flows[id].l4Proto = findL4Proto(argv[h + 1]);
#ifdef DEBUG
printf("Level 4 Protocol: %s\n", invFindL4Proto(flows[id].l4Proto));
#endif
if (flows[id].l4Proto == LX_ERROR_BYTE)
ReportErrorAndExit("General parser",
"Invalid Protocol Type", programName, id);
if (flows[id].l4Proto == L4_PROTO_ICMP) {
if ((argc > 2) && (argv[h + 2][0] != '-')) {
flows[id].icmptype = atoi(argv[h + 2]);
h += 1;
argc--;
}
}
h += 2;
argc -= 2;
break;
case 's':
if (argv[h][2] == 'p') {
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid port number",
programName, id);
SET_PORT(flows[id].SrcHost, htons(atoi(argv[h + 1])));
flows[id].srcPortSpecify = true;
h += 2;
argc -= 2;
}
else if (argv[h][2] == 'k'){
if (argc < 2)
ReportErrorAndExit("General parser", "Invalid Serial Port",
programName, id);
flows[id].serial = serialUp(argv[h + 1]);
if (flows[id].serial == INVALID_HANDLE_VALUE)
printf("Error opening interface \n");
strcpy(flows[id].serialReceiver,"noSerial");
h += 2;
argc -= 2;
#ifdef DEBUG
printf("at Sender Side %s is up \n", argv[h + 1]);
#endif
} else if (argv[h][2] == ' '){
if ((argc < 2) || ((seed = strtod(argv[h + 1], NULL)) >= 1.0)
|| (seed <= 0.0))
ReportErrorAndExit("General parser",
"Invalid seed (0 < seed < 1)", programName, id);
h += 2;
argc -= 2;
}
else {
char tempS[sizeof("What is ?") + sizeof(argv[h])];
ReportErrorAndExit("General parser", strcat(strcat(strcpy(tempS,
"What is "), argv[h]), " ?"), programName, id);
}
break;
case 'l':
if (multiFlows)
ReportErrorAndExit("General parser",
"-l option not allowed into script file", programName,
id);
logging = 1;
if ((argc < 2) || (argv[h + 1][0] == '-') || !findL7Proto(argv[h + 1])) {
strcpy(logFile, DefaultLogFile);
argc -= 1;
h += 1;
} else {
strcpy(logFile, argv[h + 1]);
argc -= 2;
h += 2;
}
break;
case 'x':
if (multiFlows)
ReportErrorAndExit("General parser",
"-x option not allowed into script file", programName,
id);
namelogReceiver = 1;
if ((argc < 2) || (argv[h + 1][0] == '-') || !findL7Proto(argv[h + 1])){
argc -= 1;
h += 1;
} else {
strcpy(logFileReceiver, argv[h+1]);
argc -= 2;
h += 2;
}
break;
case 'C':
if ((argc < 2) || (strtod(argv[h+1],NULL) <= 0.))
ReportErrorAndExit("Protocol Parser",
"Invalid pkts per sec", programName, id);
flows[id].IntArrivDistro = pdConstant;
delete flows[id].IntArriv;
ConstantRV = new Constant(1);
flows[id].IntArriv =
new SumRandom(1000.0 / strtod(argv[h+1],NULL) * (*ConstantRV));
h += 2;
argc -= 2;
break;
case 'U':
if ((argc < 3) || (strtod(argv[h+1],NULL) <= 0.)
|| (strtod(argv[h+2],NULL) <= strtod(argv[h+1],NULL)) )
ReportErrorAndExit("Protocol Parser",
"Invalid pkts per sec", programName, id);
delete flows[id].IntArriv;
flows[id].IntArrivDistro = pdUniform;
a = (1000.0 / strtod(argv[h+2],NULL));
b = (1000.0 / strtod(argv[h+1],NULL)) - a ;
UniformRV = new Uniform;
flows[id].IntArriv = new SumRandom( b * (*UniformRV) + a);
h += 3;
argc -= 3;
break;
case 'E':
if ((argc < 2) || (strtod(argv[h+1],NULL) <= 0.))
ReportErrorAndExit("Protocol Parser",
"Invalid pkts per sec", programName, id);
delete flows[id].IntArriv;
flows[id].IntArrivDistro = pdExponential;
ExponentialRV = new Exponential;
flows[id].IntArriv =
new SumRandom(1000.0 / strtod(argv[h+1],NULL) * (*ExponentialRV));
h += 2;
argc -= 2;
break;
case 'V':
if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0)
|| (strtod(argv[h + 2], NULL) <= 0))
ReportErrorAndExit("Protocol Parser",
"Invalid Pareto Distribution parameter values",
programName, id);
a = (Real) strtod(argv[h + 1], NULL);
b = (Real) strtod(argv[h + 2], NULL);
ParetoRV = new Pareto(a);
delete flows[id].IntArriv;
flows[id].IntArrivDistro = pdPareto;
flows[id].IntArriv = new SumRandom(b * (*ParetoRV));
h += 3;
argc -= 3;
break;
case 'Y':
if ((argc < 3) || (strtod(argv[h + 2], NULL) <= 0))
ReportErrorAndExit("Protocol Parser",
"Invalid pkts per sec", programName, id);
flows[id].IntArrivDistro = pdCauchy;
b = strtod(argv[h + 1], NULL);
a = strtod(argv[h + 2], NULL);
delete flows[id].IntArriv;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -