-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
106 lines (78 loc) · 2.27 KB
/
main.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Main program for router simulation.
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
#include "routerSim.h"
#include "linkedQueue.h"
using namespace std;
int main(int argc, char *argv[])
{
// *****************************************************************
// Headers...
string bars, stars;
bars.append(65, '-');
stars.append(65, '*');
string routingTableFile;
string ipAddressesFile;
string routesFile;
cout << bars << endl << "CS 302 - Assignment #6" << endl;
cout << endl;
// ----------------------------------------
// Check command line parameters (one at a time).
if (argc == 1) {
cout << "Usage: router -t <ipRoutingTable> -s <sourceIPs>";
cout << " -o <outputFile>" << endl;
return 0;
}
if (argc != 7) {
cout << "Error, invalid command line options." << endl;
return 0;
}
if (string(argv[1]) != "-t") {
cout << "main: Invalid routing table specifier." << endl;
return 0;
}
if (access(argv[2], F_OK) == -1) {
cout << "main: Error, routing table file does not exist." << endl;
return 0;
}
routingTableFile = string(argv[2]);
if (string(argv[3]) != "-s") {
cout << "main: Invalid source IP addresses file specifier." << endl;
return 0;
}
if (access(argv[4], F_OK) == -1) {
cout << "main: Error, source IP addresses file does not exist." << endl;
return 0;
}
ipAddressesFile = string(argv[4]);
if (string(argv[5]) != "-o") {
cout << "main: Invalid output file specifier." << endl;
return 0;
}
if (string(argv[6]) == "") {
cout << "main: Invalid output file." << endl;
return 0;
}
routesFile = string(argv[6]);
// ----------------------------------------
// Read routing table and show stats (for reference)
routerSim myRouter;
if (!myRouter.readRoutingTable(routingTableFile)) {
cout << "main: Error, unable to read rouing file "
<< routingTableFile << "." << endl;
return 0;
}
myRouter.showTotalRoutesCount();
myRouter.showTreeNodeCount();
myRouter.showTreeHeight();
// ----------------------------------------
// Read input file, create output file
myRouter.doRouting(ipAddressesFile, routesFile);
// *****************************************************************
// All done.
cout << endl << bars << endl;
cout << "Game Over, thank you for playing." << endl;
return 0;
}