-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOLSR.java
More file actions
141 lines (127 loc) · 4.37 KB
/
OLSR.java
File metadata and controls
141 lines (127 loc) · 4.37 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
/**
*
* @author asus
*/
public class OLSR {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException, FileNotFoundException, IOException {
// TODO code application logic here
/*
Graph g = new Graph();
g.addEdge("6", "0");
g.addEdge("6", "7");
g.addEdge("0", "1");
g.addEdge("0", "2");
g.addEdge("0", "5");
g.addEdge("7", "8");
g.addEdge("1", "0");
g.addEdge("2", "0");
g.addEdge("5", "0");
g.addEdge("6", "0");
g.addEdge("1", "7");
g.addEdge("6", "7");
g.addEdge("8", "7");
g.addEdge("0", "1");
g.addEdge("4", "1");
g.addEdge("7", "1");
g.addEdge("0", "2");
g.addEdge("3", "2");
AllPaths ap = new AllPaths(g,"6", "5");
ArrayList<String> lst = ap.getPaths();
int nNextHop = -1;
for(int i = 0 ; i < lst.size() ; i++)
{
System.out.println(lst.get(i));
String[] arrStr = lst.get(i).split(",");
if(arrStr.length > 1)
{
if(arrStr[0].equals(String.valueOf(3)))
nNextHop = Integer.parseInt(arrStr[1].trim());
}
}
System.exit(0);
*/
if(args.length < 1)
{
System.out.println("Invalid number of arguments...");
System.exit(-1);
}
if(args[0].equals("filemaker"))
{
for(int i = 0 ; i < Controller.MAX_NODE_COUNT ; i++)
{
File f_To = new File("To"+i+".txt");
File f_From = new File("From"+i+".txt");
File f_Data = new File(i+"Received.txt");
f_To.delete();
f_From.delete();
f_Data.delete();
f_To.createNewFile();
f_From.createNewFile();
}
}
if(args[0].equals("ctlr"))
{
System.out.println("Controller is Running...");
Controller ctlr = new Controller();
int i = 0 ;
while ( i < 140)
{
ctlr.DoOneCycle(i);
i++;
Thread.sleep(1000);
}
System.out.println("Controller is finishing...");
ctlr.Close();
System.out.println("Controller finished...");
}
else if(args[0].equals("router"))
{
int nNodeId = Integer.parseInt(args[1]);
int nDestinationForData = Integer.parseInt(args[2]);
String strDataToSend = "";
int nTimeToSend = -1;
if(nDestinationForData != nNodeId)
{
strDataToSend = args[3];
nTimeToSend = Integer.parseInt(args[4]);
}
IOHandler IO_handler = new IOHandler(nNodeId);
MPRManager mpr = new MPRManager(nNodeId, IO_handler);
if(nTimeToSend > -1)
mpr.SetDataTransmissionParameters(nTimeToSend, nDestinationForData, strDataToSend);
int i = 0;
System.out.println("Node "+nNodeId+" is Running...");
while( i < 120)
{
//System.out.println("Node "+nNodeId+", cycle "+i);
ArrayList<Object> lstMessages = IO_handler.ReadMessages();
mpr.HandleReceivedMessages(lstMessages);
if( i % 5 == 0)
{
mpr.SendHelloMessage();
}
if(i % 10 == 0)
{
mpr.SendTCMessage();
}
mpr.OnUpdateState(i);
i++;
Thread.sleep(1000);
}
IO_handler.CloseFiles();
System.out.println("Node "+nNodeId+" exiting...");
}
}
}