📄 source.c
字号:
/*****************************************************************************
*** Author: Hussein F. Salama ***
*** Date: September 9, 1994 ***
*** File: source.c ***
*** Functions to create and model different traffic sources ***
*****************************************************************************/
IBPSource::IBPSource(int type, int priority, Node* n, int a,
double peak, double average, double burst) {
mdl = IBP;
sn = 0;
nd = n;
stype = type;
spriority = priority;
addr = a;
pk = peak;
avg = average;
brst = burst;
double alpha = peak / (CELLSIZE / TIMESLOT);
on_slot = TIMESLOT / alpha;
off_slot = TIMESLOT;
double lambda = average / (CELLSIZE / TIMESLOT);
double c2 = burst;
double p = (alpha * (c2 - 1 + alpha) -
(alpha - 2 * lambda) * (alpha - lambda)) /
(alpha * (2 * alpha - lambda - 1 + c2));
double q = (1 - lambda * (2 - p) / alpha) / (1 - lambda / alpha);
on_off = 1 - p;
off_on = 1 - q;
};
double IBPSource::generateNext(int &jStop, int &size) {
/* simulates the Interrupted Bernoulli Process (IBP) */
double temp, t;
int state = NEXT;
jStop = False;
size = 1;
t = 0;
do {
/* now check if the IBP changes state or not */
temp = ran();
t += off_slot;
if (state == IDLE) { /* go from off to on */
if (temp <= off_on) state = ACTIVE;
}
else { /* go from on to off */
if (temp <= on_off) {
state = IDLE;
jStop = True;
}
else if (t >= on_slot) state = ACTIVE;
}
} while (state != ACTIVE);
return(t);
};
VoiceSource::VoiceSource(int type, int priority, Node* n, int a,
double peak, double rho, double burst) {
mdl = VOICE;
sn = 0;
nd = n;
stype = type;
spriority = priority;
addr = a;
pk = peak;
ro = rho;
avg = rho * peak;
brst = burst;
on_slot = CELLSIZE / peak;
off_slot = TIMESLOT;
double avgOn = burst;
double avgOff = avgOn * (1 - rho) / rho;
on_off = TIMESLOT / avgOn;
off_on = TIMESLOT / avgOff;
};
double VoiceSource::generateNext(int &jStop, int &size) {
/* simulates an on-off voice source */
double temp, t;
int state = NEXT;
jStop = False;
size = 1;
t = 0;
do {
/* now check if the voice source changes state or not */
temp = ran();
t += off_slot;
if (state == IDLE) { /* go from off to on */
if (temp <= off_on) {
if (t >= on_slot) state = ACTIVE;
else state = NEXT;
};
}
else { /* go from on to off */
if (temp <= on_off) {
state = IDLE;
jStop = True;
}
else if (t >= on_slot) {
state = ACTIVE;
t = on_slot;
};
}
} while (state != ACTIVE);
return(t);
};
VideoSource::VideoSource(int type, int priority, Node* n, int a,
double peak, double rho, double burst) {
mdl = VIDEO;
sn = 0;
nd = n;
stype = type;
spriority = priority;
addr = a;
pk = peak;
ro = rho;
avg = rho * peak;
brst = burst;
m = 10;
beta = 1 / burst;
double tmp = burst * (1 - rho) / rho;
alpha = 1 / tmp;
p = TIMESLOT / (1 / alpha);
q = TIMESLOT / (1 / beta);
currentState = (int)(ran() * m);
if (currentState != 0) currentSlot = CELLSIZE / (peak * currentState / m);
off_slot = TIMESLOT;
};
double VideoSource::generateNext(int &jStop, int &size) {
/* simulates a video source according to Maglaris model B*/
double temp, t;
double goUp = (m - currentState) * p;
double goDown = currentState * q;
jStop = False;
size = 1;
t = 0;
int done = False;
do {
/* now check if the source changes state or not */
temp = ran();
t += off_slot;
if (goDown < goUp) {
if (temp < goDown) {
currentState--;
if (currentState != 0)
currentSlot = CELLSIZE / (pk * currentState / m);
else jStop = True;
goUp = (m - currentState) * p;
goDown = currentState * q;
}
else if (temp > (1 - goUp)) {
currentState++;
currentSlot = CELLSIZE / (pk * currentState / m);
goUp = (m - currentState) * p;
goDown = currentState * q;
};
} else {
if (temp > (1 - goDown)) {
currentState--;
if (currentState != 0)
currentSlot = CELLSIZE / (pk * currentState / m);
else jStop = True;
goUp = (m - currentState) * p;
goDown = currentState * q;
}
else if (temp < goUp) {
currentState++;
currentSlot = CELLSIZE / (pk * currentState / m);
goUp = (m - currentState) * p;
goDown = currentState * q;
};
};
if ((currentState != 0) && (t > currentSlot)) {
t = currentSlot;
done = True;
}
} while (done != True);
return(t);
};
BackgroundSource::BackgroundSource(int type, int priority, Node* n, int a,
double peak, double rho, double burst) {
mdl = BACKGROUND;
sn = 0;
nd = n;
stype = type;
spriority = priority;
addr = a;
pk = peak;
ro = rho;
avg = rho * peak;
brst = burst;
m = 10;
beta = 1 / burst;
double tmp = burst * (1 - rho) / rho;
alpha = 1 / tmp;
p = TIMESLOT / (1 / alpha);
q = TIMESLOT / (1 / beta);
currentState = (int)(ran() * m);
if (currentState != 0)
currentSlot = CELLSIZE / ((peak / MEANBATCH) * currentState / m);
off_slot = TIMESLOT;
};
double BackgroundSource::generateNext(int &jStop, int &size) {
/* simulates a batch video source according to Maglaris model B*/
double temp, t;
double goUp = (m - currentState) * p;
double goDown = currentState * q;
jStop = False;
t = 0;
int done = False;
do {
/* now check if the source changes state or not */
temp = ran();
t += off_slot;
if (goDown < goUp) {
if (temp < goDown) {
currentState--;
if (currentState != 0)
currentSlot = CELLSIZE / ((pk / MEANBATCH)* currentState / m);
else jStop = True;
goUp = (m - currentState) * p;
goDown = currentState * q;
}
else if (temp > (1 - goUp)) {
currentState++;
currentSlot = CELLSIZE / ((pk / MEANBATCH)* currentState / m);
goUp = (m - currentState) * p;
goDown = currentState * q;
};
} else {
if (temp > (1 - goDown)) {
currentState--;
if (currentState != 0)
currentSlot = CELLSIZE / ((pk / MEANBATCH)* currentState / m);
else jStop = True;
goUp = (m - currentState) * p;
goDown = currentState * q;
}
else if (temp < goUp) {
currentState++;
currentSlot = CELLSIZE / ((pk / MEANBATCH)* currentState / m);
goUp = (m - currentState) * p;
goDown = currentState * q;
};
};
if ((currentState != 0) && (t > currentSlot)) {
t = currentSlot;
//Calculate the batch size
size = 1;
while (ran() < (1 - (1.0 / MEANBATCH))) size++;
done = True;
}
} while (done != True);
return(t);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -