📄 traf.c
字号:
/*****************************************************************************
*** Author: Hussein F. Salama ***
*** Date: September 9, 1994 ***
*** File: traf.c ***
*** Functions to handle arrivals/departures of packets to/from a node ***
***
*****************************************************************************/
void Node::trafficIn(Data *d, double t_global, TheEventList *E,
TheNodeList *N, int stats) {
/* this routine implements the transfer of a packet from an input link to *
* the queue of a node */
//printf("traffic into node %d from source %d at time %lf\n", name(),
// ((Node*)(d->source()))->name(), t_global);
//printf("packet issued at %lf\n", d->time());
//Statistics
if (stats == True) N->statistics(this, d, t_global);
RoutingTableEntry *tmp1 = rte;
//put data packet in the queue of a node iff it will be forwarded further
int found = False;
while ((tmp1 != NULL) && (found == False)) {
if ((tmp1->address() == d->address()) && (tmp1->source() == d->source()))
found = True;
else tmp1 = tmp1->next();
};
if (found == True) {
// put the data packet in the queue
Node *tempChild;
NodeListEntry *tmp2;
AdjacencyListEntry *tmp3;
tmp2 = tmp1->children();
while (tmp2 != NULL) {
tempChild = tmp2->nodePtr();
tmp3 = ale;
while ((tmp3 != NULL) && (tmp3->nodePtr() != tempChild))
tmp3 = tmp3->next();
if (tmp3 != NULL) {
Queue *q = tmp3->queue();
short s = q->add_to_q((*d));
if (s == WasNotFull) { //if packet was accepted
if ((q->packetsInQ() == 1) && (tmp3->busy() == False)) {
//then send the packet directly out of the queue
double t = t_global + (CELLSIZE/tmp3->linkCapacity());
Data *dd = new Data;
*dd = q->remove_from_q();
tmp3->busy(True);
E->insertEvent(top, tmp3, dd->type() + 3, t, dd);
};
};
};
tmp2 = tmp2->next();
};
};
delete d;
};
void AdjacencyListEntry::trafficOut(Data *d, double t_global, TheEventList *E) {
//remove one packet from the queue and forward it to the children nodes
//printf("traffic out at time %lf to node %d\n", t_global, nd->name());
//printf("packet issued at time %lf from source %d\n", d->time(),
// ((Node *)(d->source()))->name());
double t;
bsy = False;
if ((d->type() != Nonsense) && (d->type() != Background)) {
t = t_global + Tswitching + (Tpropagation * dist);
E->insertEvent(bottom, nd, d->type() + 1, t, d);
}
else delete d;
if ((q->QisMT() == False) && (bsy == False)) {
//generate the event for the next packet leaving the queue
t = t_global + (CELLSIZE/cpcty);
Data *dd = new Data;
*dd = q->remove_from_q();
bsy = True;
E->insertEvent(top, this, dd->type() + 3, t, dd);
/* the data cell passed to insertEvent may not be the actually
transmitted cell. If a higher priority cell arrives before
t, that higher priority cell will be transmitted first. */
};
};
void Source::sourceToNode(Data *d, double t_global, TheEventList *E,
TheNodeList *N, int stats) {
/* this routine implements the transfer of a packet from a source to *
* the queue of a node */
//printf(" From Source to Node %d at time %lf\n", nodePtr()->name(), t_global);
//Statistics
if (stats == True)
N->statistics((Node *)(d->source()), d, t_global);
double t;
RoutingTableEntry *tmp1 = nd->routingTable();
if (stype == Background) {
AdjacencyListEntry *adj = nd->adjacentNodes();
while ((adj != NULL) && (adj->nodePtr()->name() != addr))
adj = adj->next();
if (adj != NULL) {
Queue *q = adj->queue();
short s = q->add_to_q((*d));
if (s == WasNotFull) {
//if packet was accepted
if ((q->packetsInQ() == 1) && (adj->busy() == False)) {
//then send the packet directly out of the queue
t = t_global + (CELLSIZE/adj->linkCapacity());
Data *dd = new Data;
*dd = q->remove_from_q();
adj->busy(True);
E->insertEvent(top, adj, dd->type() + 3, t, dd);
};
};
};
}
else {
int found = False;
while ((tmp1 != NULL) && (found == False)) {
if ((tmp1->address() == addr) && (tmp1->source() == nodePtr()))
found = True;
else tmp1 = tmp1->next();
};
if (found == True) {
// put the data packet in the queue
Node *tempChild;
NodeListEntry *tmp2;
AdjacencyListEntry *tmp3;
tmp2 = tmp1->children();
while (tmp2 != NULL) {
tempChild = tmp2->nodePtr();
tmp3 = nd->adjacentNodes();
while ((tmp3 != NULL) && (tmp3->nodePtr() != tempChild))
tmp3 = tmp3->next();
if (tmp3 != NULL) {
Queue *q = tmp3->queue();
short s = q->add_to_q((*d));
if (s == WasNotFull) { //if packet was accepted
if ((q->packetsInQ() == 1) && (tmp3->busy() == False)) {
//then send the packet directly out of the queue
t = t_global + (CELLSIZE/tmp3->linkCapacity());
Data *dd = new Data;
*dd = q->remove_from_q();
tmp3->busy(True);
E->insertEvent(top, tmp3, dd->type() + 3, t, dd);
};
};
};
tmp2 = tmp2->next();
};
};
};
// Generate the next packet from that source
int jStop, size, i;
t = t_global + generateNext(jStop, size);
for (i = 0; i < size; i++) {
sn++;
Data *dd = new Data(sn, stype, spriority, t, addr, nd, jStop);
//create the event for the next packet from the source
E->insertEvent(bottom, this, stype + 5, t, dd);
delete d;
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -