-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.cpp
More file actions
28 lines (24 loc) · 900 Bytes
/
router.cpp
File metadata and controls
28 lines (24 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "router.h"
#include <iostream>
Router::~Router()
{
routingTable_.clear();
}
void Router::receiving()
{
bool isTrue = false;
for(int i = 0; i < (int)routingTable_.size(); ++i)
{
if(routingTable_[i].destination == packets->destAddress())
{
isTrue = true;
std::cout << "Router #" << id() << ": forwarding packet (from: " << packets->srcAddress().toString() << ", to: " << packets->destAddress().toString() << ", " << packets->dataString().length() << "bytes)" << std::endl;
routingTable_[i].nextLink->whatLink(this, packets);
break;
}
}
if (!isTrue)
{
std::cout << "Router #" << id() << ": no router for packet (from: " << packets->srcAddress().toString() << ", to: " << packets->destAddress().toString() << ", " << packets->dataString().length() << " bytes)" << std::endl;
}
}