forked from scarecrow2003/cs5229hw2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolicy.py
executable file
·624 lines (589 loc) · 27.6 KB
/
Policy.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
#!/usr/bin/python
"""
@Author <Su Zhihua/A0195041L>
Date : 05/09/2019
"""
import httplib
import json
import time
class flowStat(object):
def __init__(self, server):
self.server = server
def get(self, switch):
ret = self.rest_call({}, 'GET', switch)
return json.loads(ret[2])
def rest_call(self, data, action, switch):
path = '/wm/core/switch/' + switch + "/flow/json"
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
}
body = json.dumps(data)
conn = httplib.HTTPConnection(self.server, 8080)
# print path
conn.request(action, path, body, headers)
response = conn.getresponse()
ret = (response.status, response.reason, response.read())
conn.close()
return ret
class StaticFlowPusher(object):
def __init__(self, server):
self.server = server
def get(self, data):
ret = self.rest_call({}, 'GET')
return json.loads(ret[2])
def set(self, data):
ret = self.rest_call(data, 'POST')
return ret[0] == 200
def remove(self, objtype, data):
ret = self.rest_call(data, 'DELETE')
return ret[0] == 200
def rest_call(self, data, action):
path = '/wm/staticflowpusher/json'
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
}
body = json.dumps(data)
conn = httplib.HTTPConnection(self.server, 8080)
conn.request(action, path, body, headers)
response = conn.getresponse()
ret = (response.status, response.reason, response.read())
# print ret
conn.close()
return ret
pusher = StaticFlowPusher('127.0.0.1')
flowget = flowStat('127.0.0.1')
# To insert the policies for the traffic applicable to path between S1 and S2
def S1toS2():
# For switch S1, use q1, which limits to 1Mbps, to limit the traffic from h1 to h2
S1H1ToH2Limit = {'switch': "00:00:00:00:00:00:00:01",
"name": "S1h1toh2limit",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.2",
"active": "true",
"actions": "set_queue=1,output=2"}
# For switch S2, use q1, which limits to 1Mbps, to limit the traffic from h1 to h2
S2H1ToH2Limit = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h1toh2limit",
"cookie": "0",
"priority": "2",
"in_port": "2",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.2",
"active": "true",
"actions": "set_queue=1,output=1"}
pusher.set(S1H1ToH2Limit)
pusher.set(S2H1ToH2Limit)
# To insert the policies for the traffic applicable to path between S2 and S3
def S2toS3():
# For switch S2, block traffic from h2 to h3 for UDP port 1000 ~ 1007
S2H2ToH3Block1 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block1",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x03e8/0xfff8",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h2 to h3 for UDP port 1008 ~ 1023
S2H2ToH3Block2 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block2",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x03f0/0xfff0",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h2 to h3 for UDP port 1024 ~ 1087
S2H2ToH3Block3 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block3",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0400/0xffc0",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h2 to h3 for UDP port 1088 ~ 1095
S2H2ToH3Block4 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block4",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0440/0xfff8",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h2 to h3 for UDP port 1096 ~ 1099
S2H2ToH3Block5 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block5",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0448/0xfffc",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h2 to h3 for UDP port 1100
S2H2ToH3Block6 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h2toh3block6",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "1100",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1000 ~1007
S2H3ToH2Block1 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block1",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x03e8/0xfff8",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1008 ~1023
S2H3ToH2Block2 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block2",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x03f0/0xfff0",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1024 ~1087
S2H3ToH2Block3 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block3",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0400/0xffc0",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1088 ~1095
S2H3ToH2Block4 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block4",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0440/0xfff8",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1096 ~1099
S2H3ToH2Block5 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block5",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0448/0xfffc",
"active": "true",
"actions": ""}
# For switch S2, block traffic from h3 to h2 for UDP port 1100
S2H3ToH2Block6 = {'switch': "00:00:00:00:00:00:00:02",
"name": "S2h3toh2block6",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "1100",
"active": "true",
"actions": ""}
pusher.set(S2H2ToH3Block1)
pusher.set(S2H2ToH3Block2)
pusher.set(S2H2ToH3Block3)
pusher.set(S2H2ToH3Block4)
pusher.set(S2H2ToH3Block5)
pusher.set(S2H2ToH3Block6)
pusher.set(S2H3ToH2Block1)
pusher.set(S2H3ToH2Block2)
pusher.set(S2H3ToH2Block3)
pusher.set(S2H3ToH2Block4)
pusher.set(S2H3ToH2Block5)
pusher.set(S2H3ToH2Block6)
# For switch S3, block traffic from h2 to h3 for UDP port 1000 ~ 1007
S3H2ToH3Block1 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block1",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x03e8/0xfff8",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h2 to h3 for UDP port 1008 ~ 1023
S3H2ToH3Block2 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block2",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x03f0/0xfff0",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h2 to h3 for UDP port 1024 ~ 1087
S3H2ToH3Block3 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block3",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0400/0xffc0",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h2 to h3 for UDP port 1088 ~ 1095
S3H2ToH3Block4 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block4",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0440/0xfff8",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h2 to h3 for UDP port 1096 ~ 1099
S3H2ToH3Block5 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block5",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "0x0448/0xfffc",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h2 to h3 for UDP port 1100
S3H2ToH3Block6 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h2toh3block6",
"cookie": "0",
"priority": "2",
"in_port": "3",
"eth_type": "0x800",
"ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x11",
"udp_dst": "1100",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1000 ~1007
S3H3ToH2Block1 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block1",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x03e8/0xfff8",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1008 ~1023
S3H3ToH2Block2 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block2",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x03f0/0xfff0",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1024 ~1087
S3H3ToH2Block3 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block3",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0400/0xffc0",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1088 ~1095
S3H3ToH2Block4 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block4",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0440/0xfff8",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1096 ~1099
S3H3ToH2Block5 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block5",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "0x0448/0xfffc",
"active": "true",
"actions": ""}
# For switch S3, block traffic from h3 to h2 for UDP port 1100
S3H3ToH2Block6 = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h3toh2block6",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2",
"ip_proto": "0x11",
"udp_dst": "1100",
"active": "true",
"actions": ""}
pusher.set(S3H2ToH3Block1)
pusher.set(S3H2ToH3Block2)
pusher.set(S3H2ToH3Block3)
pusher.set(S3H2ToH3Block4)
pusher.set(S3H2ToH3Block5)
pusher.set(S3H2ToH3Block6)
pusher.set(S3H3ToH2Block1)
pusher.set(S3H3ToH2Block2)
pusher.set(S3H3ToH2Block3)
pusher.set(S3H3ToH2Block4)
pusher.set(S3H3ToH2Block5)
pusher.set(S3H3ToH2Block6)
# To insert the policies for the traffic applicable to path between S1 and S3
def S1toS3():
# For switch S1, limit the traffic to 1Mbps for http
S1H1ToH3Limit1M = {'switch': "00:00:00:00:00:00:00:01",
"name": "S1h1toh3limit1m",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x06",
"tcp_dst": "80",
"active": "true",
"actions": "set_queue=1,output=3"}
# For switch S3, limit the traffic to 1Mbps for http
S3H1ToH3Limit1M = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h1toh3limit1m",
"cookie": "0",
"priority": "2",
"in_port": "2",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x06",
"tcp_dst": "80",
"active": "true",
"actions": "set_queue=1,output=1"}
# For switch S1, limit the traffic to 512Kbps for http
S1H1ToH3Limit512K = {'switch': "00:00:00:00:00:00:00:01",
"name": "S1h1toh3limit512k",
"cookie": "0",
"priority": "2",
"in_port": "1",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x06",
"tcp_dst": "80",
"active": "true",
"actions": "set_queue=2,output=3"}
# For switch S3, limit the traffic to 512KMbps for http
S3H1ToH3Limit1512K = {'switch': "00:00:00:00:00:00:00:03",
"name": "S3h1toh3limit512k",
"cookie": "0",
"priority": "2",
"in_port": "2",
"eth_type": "0x800",
"ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3",
"ip_proto": "0x06",
"tcp_dst": "80",
"active": "true",
"actions": "set_queue=2,output=1"}
pusher.set(S1H1ToH3Limit1M)
pusher.set(S3H1ToH3Limit1M)
limited = False # Set to True when limited to 512Kbps, False when limite to 1Mbps
current_limit = 0 # current limit that when bit count reaches to switch policy
ten = 10 * 1024 * 1024
twenty = 2 * ten
current_limit += twenty
while True:
response = flowget.get("00:00:00:00:00:00:00:01")
policy_count = len(response['flows'])
for i in range(policy_count):
policy = response['flows'][i]
policy_match = policy['match']
if 'eth_type' in policy_match and policy_match['eth_type'] == '0x0x800' and 'ip_proto' in policy_match \
and policy_match['ip_proto'] == '0x6' and 'tcp_dst' in policy_match and policy_match['tcp_dst'] == '80' \
and 'ipv4_src' in policy_match and policy_match['ipv4_src'] == '10.0.0.1' and 'ipv4_dst' in policy_match \
and policy_match['ipv4_dst'] == '10.0.0.3' and 'in_port' in policy_match and policy_match['in_port'] == '1':
print "find matching policy"
byte_count = policy['byteCount']
bit_count = int(byte_count) * 8
if bit_count > current_limit:
# if bit count is greater than current limit, we switch policy and increase the current_limit
if limited:
print "set to 1Mbps limit"
pusher.set(S1H1ToH3Limit1M)
pusher.set(S3H1ToH3Limit1M)
current_limit += twenty
else:
print "set to 512Kbps limit"
pusher.set(S1H1ToH3Limit512K)
pusher.set(S3H1ToH3Limit1512K)
current_limit += ten
limited = not limited
# since the traffic is rate limited, it needs 20 second to reach the next limit if it run in full
# speed, so we can sleep at least 20 second to do the next query. to play safe, we sleep 18 seconds
time.sleep(18)
else:
# if bit count is less than current limit, we sleep to wait for more traffic. the time to sleep is
# calculated based on remaining bit and traffic speed. to play safe, we sleep 2 second less
print "wait for more traffic"
remaining = current_limit - bit_count
remaining_time = remaining / (512 * 1024)
if not limited:
remaining_time /= 2
if remaining_time - 2 > 0:
time.sleep(remaining_time - 2)
break
else:
# if there is no matching policy found, we wait for 1 second to query again
time.sleep(1)
def staticForwarding():
# Below 4 flows are for setting up the static forwarding for the path H1->S1->S2->H2 & vice-versa
# Define static flow for Switch S1 for packet forwarding b/w h1 and h2
S1Staticflow1 = {'switch': "00:00:00:00:00:00:00:01", "name": "S1h1toh2", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.2", "active": "true", "actions": "output=2"}
S1Staticflow2 = {'switch': "00:00:00:00:00:00:00:01", "name": "S1h2toh1", "cookie": "0",
"priority": "1", "in_port": "2", "eth_type": "0x800", "ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.1", "active": "true", "actions": "output=1"}
# Define static flow for Switch S2 for packet forwarding b/w h1 and h2
S2Staticflow1 = {'switch': "00:00:00:00:00:00:00:02", "name": "S2h2toh1", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.1", "active": "true", "actions": "output=2"}
S2Staticflow2 = {'switch': "00:00:00:00:00:00:00:02", "name": "S2h1toh2", "cookie": "0",
"priority": "1", "in_port": "2", "eth_type": "0x800", "ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.2", "active": "true", "actions": "output=1"}
# Below 4 flows are for setting up the static forwarding for the path H1->S1->S3->H3 & vice-versa
# Define static flow for Switch S1 for packet forwarding b/w h1 and h3
S1Staticflow3 = {'switch': "00:00:00:00:00:00:00:01", "name": "S1h1toh3", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3", "active": "true", "actions": "output=3"}
S1Staticflow4 = {'switch': "00:00:00:00:00:00:00:01", "name": "S1h3toh1", "cookie": "0",
"priority": "1", "in_port": "3", "eth_type": "0x800", "ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.1", "active": "true", "actions": "output=1"}
# Define static flow for Switch S3 for packet forwarding b/w h1 and h3
S3Staticflow1 = {'switch': "00:00:00:00:00:00:00:03", "name": "S3h3toh1", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.1", "active": "true", "actions": "output=2"}
S3Staticflow2 = {'switch': "00:00:00:00:00:00:00:03", "name": "S3h1toh3", "cookie": "0",
"priority": "1", "in_port": "2", "eth_type": "0x800", "ipv4_src": "10.0.0.1",
"ipv4_dst": "10.0.0.3", "active": "true", "actions": "output=1"}
# Below 4 flows are for setting up the static forwarding for the path H2->S2->S3->H3 & vice-versa
# Define static flow for Switch S1 for packet forwarding b/w h2 and h3
S2Staticflow3 = {'switch': "00:00:00:00:00:00:00:02", "name": "S2h2toh3", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3", "active": "true", "actions": "output=3"}
S2Staticflow4 = {'switch': "00:00:00:00:00:00:00:02", "name": "S2h3toh2", "cookie": "0",
"priority": "1", "in_port": "3", "eth_type": "0x800", "ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2", "active": "true", "actions": "output=1"}
# Define static flow for Switch S3 for packet forwarding b/w h2 and h3
S3Staticflow3 = {'switch': "00:00:00:00:00:00:00:03", "name": "S3h3toh2", "cookie": "0",
"priority": "1", "in_port": "1", "eth_type": "0x800", "ipv4_src": "10.0.0.3",
"ipv4_dst": "10.0.0.2", "active": "true", "actions": "output=3"}
S3Staticflow4 = {'switch': "00:00:00:00:00:00:00:03", "name": "S3h2toh3", "cookie": "0",
"priority": "1", "in_port": "2", "eth_type": "0x800", "ipv4_src": "10.0.0.2",
"ipv4_dst": "10.0.0.3", "active": "true", "actions": "output=1"}
# Now, Insert the flows to the switches
pusher.set(S1Staticflow1)
pusher.set(S1Staticflow2)
pusher.set(S1Staticflow3)
pusher.set(S1Staticflow4)
pusher.set(S2Staticflow1)
pusher.set(S2Staticflow2)
pusher.set(S2Staticflow3)
pusher.set(S2Staticflow4)
pusher.set(S3Staticflow1)
pusher.set(S3Staticflow2)
pusher.set(S3Staticflow3)
pusher.set(S3Staticflow4)
if __name__ == '__main__':
staticForwarding()
S1toS2()
S2toS3()
S1toS3()
pass