Commit e62637d2 authored by Robert Ricci's avatar Robert Ricci

Added files missed in my last commit.

parent 1080662b
/*
* Copyright (c) 1999-2001 The University of Utah and the Flux Group.
* All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
/*
* Dumb as a stump config for options that the test program supports
*/
void
parse_options(char **argv, struct config_param options[], int nopt)
{
extern char **environ;
/* get from environment first */
config_parse(environ, options, nopt);
/* then command line */
config_parse(argv, options, nopt);
}
int
config_parse(char **args, struct config_param cparams[], int nparams)
{
int i, j, len;
char *arg, *var, *val, buf[256];
for (i = 0, arg = args[i]; arg != 0; i++, arg = args[i]) {
len = sizeof(buf) - 1;
strncpy(buf, arg, len);
buf[len] = 0;
var = val = buf;
if (strsep(&val, "=") == 0 || val == 0 || *val == 0)
continue;
for (j = 0; j < nparams; j++)
if (strcmp(var, cparams[j].name) == 0)
break;
if (j == nparams)
continue;
if (cparams[j].func) {
cparams[j].func(&cparams[j], val);
continue;
}
switch (cparams[j].type) {
case CONFIG_INT:
*(int *)cparams[j].ptr = atoi(val);
break;
case CONFIG_FLOAT:
*(float *)cparams[j].ptr = (float) atof(val);
break;
/*
case CONFIG_STRING:
bp = malloc(strlen(val) + 1);
assert(bp);
strcpy(bp, val);
*(char **)cparams[j].ptr = bp;
break;
*/
}
}
return 0;
}
void
dump_options(const char *str, struct config_param cparams[], int numparams)
{
int i;
fprintf(stderr,"%s configuration:\n", str);
for (i = 0; i < numparams; i++) {
fprintf(stderr," %s ", cparams[i].name);
switch (cparams[i].type) {
case CONFIG_INT:
fprintf(stderr,"%d\n",
*(int *)cparams[i].ptr);
break;
case CONFIG_FLOAT:
fprintf(stderr,"%f\n",
*(float *)cparams[i].ptr);
break;
/*
case CONFIG_STRING:
fprintf(stderr,"%s\n", *(char **)cparams[i].ptr ?
*(char **)cparams[i].ptr : "<unset>");
break;
*/
}
}
}
#ifndef __DELAY_H
#define __DELAY_H
class tb_pnode;
template <class T> inline double basic_distance(T a,T b) {
if (b == 0) {
if (a == 0)
return 0;
else
return DBL_MAX;
}
return fabs((double)a/(double)b - 1.0);
}
inline double delay_distance(int a, int b) {
return basic_distance(a,b);
}
inline double bandwidth_distance(int a,int b) {
return basic_distance(a,b);
}
inline double loss_distance(double a,double b) {
return basic_distance(a,b);
}
class tb_delay_info {
public:
int bandwidth;
int delay;
double loss;
int bw_under,bw_over;
int delay_under,delay_over;
double loss_under,loss_over;
double bw_weight,delay_weight,loss_weight;
double distance(tb_delay_info &target) {
// ricci - hack to try to remove this behavior
return 0;
if (((bw_under != -1) && (target.bandwidth < bandwidth-bw_under)) ||
((bw_over != -1) && (target.bandwidth > bandwidth+bw_over)) ||
((delay_under != -1) && (target.delay < delay-delay_under)) ||
((delay_over != -1) && (target.delay > delay+delay_over)) ||
((loss_under != -1) && (target.loss < loss-loss_under)) ||
((loss_over != -1) && (target.loss > loss+loss_over))) {
return -1;
}
return bandwidth_distance(target.bandwidth,bandwidth)*bw_weight+
delay_distance(target.delay,delay)*delay_weight+
loss_distance(target.loss,loss)*loss_weight;
}
friend ostream &operator<<(ostream &o, const tb_delay_info& delay)
{
o << "tb_delay_info: bw=" << delay.bandwidth << "+" <<
delay.bw_over << "-" << delay.bw_under << "/" << delay.bw_weight;
o << " delay=" << delay.delay << "+" << delay.delay_over <<
"-" << delay.delay_under << "/" << delay.delay_weight;
o << " loss=" << delay.loss << "+" << delay.loss_over << "-" <<
delay.loss_under << "/" << delay.loss_weight;
o << endl;
return o;
}
};
#endif __DELAY_H
#include <vector>
#include <rope>
#include <algo.h>
#include <iostream.h>
#include "parser.h"
string_vector split_line(crope line,char split_char)
{
string_vector parsed;
crope::const_iterator next_space,prev_space;
prev_space = line.begin();
while ((next_space = find(prev_space,line.end(),' ')) != line.end()) {
parsed.push_back(line.substr(prev_space,next_space));
prev_space = ++next_space;
}
if (prev_space != next_space)
parsed.push_back(line.substr(prev_space,next_space));
return parsed;
}
int split_two(crope line,char split_char,crope &a,crope &b,crope default_b)
{
crope::const_iterator space = find(line.begin(),line.end(),split_char);
a = line.substr(line.begin(),space);
if (space != line.end()) {
b = line.substr(++space,line.end());
return 0;
} else {
b = default_b;
return 1;
}
}
int split_two(crope line,char split_char,crope &a,crope &b)
{
return split_two(line,split_char,a,b,"");
}
#ifndef __PARSER_H
#define __PARSER_H
typedef vector<crope> string_vector;
int split_two(crope line,char split_char,crope &a,crope &b);
int split_two(crope line,char split_char,crope &a,crope &b,crope default_b);
string_vector split_line(crope line,char split_char);
#endif
// This file may need to be changed depending on the architecture.
#include <limits.h>
#define WCHAR_MIN INT_MIN
#define WCHAR_MAX INT_MAX
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment