-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (54 loc) · 1.84 KB
/
main.cpp
File metadata and controls
61 lines (54 loc) · 1.84 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "node.h"
vector<RoutingNode*> distanceVectorNodes;
void routingAlgo(vector<RoutingNode*> distanceVectorNodes);
int main() {
int n; // number of nodes
cin>>n;
string name; //Node label
distanceVectorNodes.clear();
for (int i = 0 ; i < n; i++) {
RoutingNode *newnode = new RoutingNode();
cin>>name;
newnode->setName(name);
distanceVectorNodes.push_back(newnode);
}
cin>>name;
/*
For each node label(@name), it's own ip address, ip address of another node
defined by @oname will be inserted in the node's own datastructure interfaces
*/
while(name != "EOE") { //End of entries
for (int i =0 ; i < distanceVectorNodes.size(); i++) {
string myeth,oeth, oname;
if(distanceVectorNodes[i]->getName() == name) {
//node interface ip
cin>>myeth;
//ip of another node connected to myeth (nd[i])
cin>>oeth;
//label of the node whose ip is oeth
cin>>oname;
for(int j = 0 ; j < distanceVectorNodes.size(); j++) {
if(distanceVectorNodes[j]->getName() == oname) {
/*
@myeth: ip address of my (distanceVectorNodes[i]) end of connection.
@oeth: ip address of other end of connection.
@distanceVectorNodes[j]: pointer to the node whose one of the interface is @oeth
*/
distanceVectorNodes[i]->addInterface(myeth, oeth, distanceVectorNodes[j]);
//Routing table initialization
/*
@myeth: ip address of my (distanceVectorNodes[i]) ethernet interface.
@0: hop count, 0 as node does not need any other hop to pass packet to itself.
*/
distanceVectorNodes[i]->addTblEntry(myeth, 0);
break;
}
}
}
}
cin>>name;
}
/* The logic of the routing algorithm should go here */
routingAlgo(distanceVectorNodes);
/* Add the logic for periodic update (after every 1 sec) here */
}