forked from axbryd/FlowBlaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_balancer.xl
53 lines (43 loc) · 876 Bytes
/
load_balancer.xl
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
import "pkt_headers.xlh";
PacketField ethByte {
dst = packet.data[5:+1];
}
Constant PKT = 255;
Stage loadBalancer {
Register global counter, ZERO;
setFlowKey(tcp.sport, tcp.dport);
State initial init {
on(pktRcvd) {
if(pktRcvd.port == 1, counter > ZERO) {
counter = counter - 1;
setField(ethByte.dst, PKT, 0xaa);
sendPacket(PKT, 2);
setNextState(server1);
}
if(pktRcvd.port == 1, counter == ZERO) {
counter = counter + 1;
setField(ethByte.dst, PKT, 0xbb);
sendPacket(PKT, 3);
setNextState(server2);
}
}
}
State server1 {
setField(ethByte.dst, PKT, 0xaa);
sendPacket(PKT, 2);
}
State server2 {
setField(ethByte.dst, PKT, 0xbb);
sendPacket(PKT, 3);
}
State any {
on(pktRcvd) {
if(pktRcvd.port ==2 ) {
sendPacket(PKT, 1);
}
if(pktRcvd.port ==3 ) {
sendPacket(PKT, 1);
}
}
}
}