-
Notifications
You must be signed in to change notification settings - Fork 0
/
consoles.py
executable file
·785 lines (640 loc) · 24.3 KB
/
consoles.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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
#!/usr/bin/python
"""
consoles.py: bring up a bunch of miniature consoles on a virtual network
This demo shows how to monitor a set of nodes by using
Node's monitor() and Tkinter's createfilehandler().
We monitor nodes in a couple of ways:
- First, each individual node is monitored, and its output is added
to its console window
- Second, each time a console window gets iperf output, it is parsed
and accumulated. Once we have output for all consoles, a bar is
added to the bandwidth graph.
The consoles also support limited interaction:
- Pressing "return" in a console will send a command to it
- Pressing the console's title button will open up an xterm
Bob Lantz, April 2010
"""
import time
import re
import commands
from Tkinter import Frame, Button, Label, Text, Scrollbar, Canvas, Wm, READABLE
from mininet.log import setLogLevel
from mininet.topolib import TreeNet
from mininet.term import makeTerms, cleanUpScreens
from mininet.util import quietRun
from mininet.node import Node
from mininet.topo import Topo
from mininet.net import Mininet
servers = 0
nathost = 0
clients = 6
start = 1
number = 0
watch = 0
local_program_path = "/usr/local/sbin"
global start_how_many
start_how_many = 1
class MyNode(Node):
def __init__(self):
Node.__init__(self)
class MyTopo(Topo):
"Simple topology example."
def __init__(self):
"Create custom topo."
# Initialize topology
Topo.__init__(self)
# Add hosts and switches
s1 = self.addSwitch('s1')
for i in range(1, servers + clients + 1):
mac = hex(i).replace('0x', '')
mac = '0' * (12 - len(mac)) + mac
for j in range(5, 0, -1):
mac = mac[0: j * 2] + ':' + mac[j * 2: len(mac)]
exec ("vland_" + str(i) + "= self.addHost('vland_" + str(i) + "', mac='" + mac + "')")
exec ("self.addLink(s1" + ", vland_" + str(i) + ")")
topos = {'mytopo': (lambda: MyTopo())}
class Console(Frame):
"A simple console on a host."
def __init__(self, parent, net, node, height=10, width=32, title='Node'):
Frame.__init__(self, parent)
self.net = net
self.node = node
self.prompt = node.name + '# '
self.height, self.width, self.title = height, width, title
# Initialize widget styles
self.buttonStyle = {'font': 'Monaco 14'}
self.textStyle = {
'font': 'Monaco 14',
'bg': 'black',
'fg': 'green',
'width': self.width,
'height': self.height,
'relief': 'sunken',
'insertbackground': 'green',
'highlightcolor': 'green',
'selectforeground': 'black',
'selectbackground': 'green'
}
# Set up widgets
self.text = self.makeWidgets()
self.bindEvents()
self.sendCmd('export TERM=dumb')
self.outputHook = None
def makeWidgets(self):
"Make a label, a text area, and a scroll bar."
def newTerm(net=self.net, node=self.node, title=self.title):
"Pop up a new terminal window for a node."
net.terms += makeTerms([node], title)
label = Button(self, text=self.node.name, command=newTerm,
**self.buttonStyle)
label.pack(side='top', fill='x')
text = Text(self, wrap='word', **self.textStyle)
ybar = Scrollbar(self, orient='vertical', width=7,
command=text.yview)
text.configure(yscrollcommand=ybar.set)
text.pack(side='left', expand=True, fill='both')
ybar.pack(side='right', fill='y')
return text
def bindEvents(self):
"Bind keyboard and file events."
# The text widget handles regular key presses, but we
# use special handlers for the following:
self.text.bind('<Control-c>', self.handlec)
self.text.bind('<Control-v>', self.handlev)
self.text.bind('<Return>', self.handleReturn)
self.text.bind('<Control-d>', self.handleInt)
self.text.bind('<KeyPress>', self.handleKey)
# This is not well-documented, but it is the correct
# way to trigger a file event handler from Tk's
# event loop!
self.tk.createfilehandler(self.node.stdout, READABLE,
self.handleReadable)
# We're not a terminal (yet?), so we ignore the following
# control characters other than [\b\n\r]
ignoreChars = re.compile(r'[\x00-\x07\x09\x0b\x0c\x0e-\x1f]+')
def append(self, text):
"Append something to our text frame."
text = self.ignoreChars.sub('', text)
self.text.insert('end', text)
self.text.mark_set('insert', 'end')
self.text.see('insert')
outputHook = lambda x, y: True # make pylint happier
if self.outputHook:
outputHook = self.outputHook
outputHook(self, text)
def handlec(self, event):
if self.node.waiting:
self.node.write(event.char)
def handlev(self, event):
if self.node.waiting:
self.node.write(event.char)
def handleKey(self, event):
"If it's an interactive command, send it to the node."
char = event.char
if self.node.waiting:
self.node.write(char)
def handleReturn(self, event):
"Handle a carriage return."
cmd = self.text.get('insert linestart', 'insert lineend')
# Send it immediately, if "interactive" command
if self.node.waiting:
self.node.write(event.char)
return
# Otherwise send the whole line to the shell
pos = cmd.find(self.prompt)
if pos >= 0:
cmd = cmd[pos + len(self.prompt):]
self.sendCmd(cmd)
# Callback ignores event
def handleInt(self, _event=None):
"Handle control-c."
self.node.sendInt()
def sendCmd(self, cmd):
"Send a command to our node."
if not self.node.waiting:
self.node.sendCmd(cmd)
def handleReadable(self, _fds, timeoutms=None):
"Handle file readable event."
data = self.node.monitor(timeoutms)
self.append(data)
if not self.node.waiting:
# Print prompt
self.append(self.prompt)
def waiting(self):
"Are we waiting for output?"
return self.node.waiting
def waitOutput(self):
"Wait for any remaining output."
while self.node.waiting:
# A bit of a trade-off here...
self.handleReadable(self, timeoutms=1000)
self.update()
def clear(self):
"Clear all of our text."
self.text.delete('1.0', 'end')
class Graph(Frame):
"Graph that we can add bars to over time."
def __init__(self, parent=None, bg='white', gheight=200, gwidth=500,
barwidth=10, ymax=3.5, ):
Frame.__init__(self, parent)
self.bg = bg
self.gheight = gheight
self.gwidth = gwidth
self.barwidth = barwidth
self.ymax = float(ymax)
self.xpos = 0
# Create everything
self.title, self.scale, self.graph = self.createWidgets()
self.updateScrollRegions()
self.yview('moveto', '1.0')
def createScale(self):
"Create a and return a new canvas with scale markers."
height = float(self.gheight)
width = 25
ymax = self.ymax
scale = Canvas(self, width=width, height=height,
background=self.bg)
opts = {'fill': 'red'}
# Draw scale line
scale.create_line(width - 1, height, width - 1, 0, **opts)
# Draw ticks and numbers
for y in range(0, int(ymax + 1)):
ypos = height * (1 - float(y) / ymax)
scale.create_line(width, ypos, width - 10, ypos, **opts)
scale.create_text(10, ypos, text=str(y), **opts)
return scale
def updateScrollRegions(self):
"Update graph and scale scroll regions."
ofs = 20
height = self.gheight + ofs
self.graph.configure(scrollregion=(0, -ofs,
self.xpos * self.barwidth, height))
self.scale.configure(scrollregion=(0, -ofs, 0, height))
def yview(self, *args):
"Scroll both scale and graph."
self.graph.yview(*args)
self.scale.yview(*args)
def createWidgets(self):
"Create initial widget set."
# Objects
title = Label(self, text='Bandwidth (Gb/s)', bg=self.bg)
width = self.gwidth
height = self.gheight
scale = self.createScale()
graph = Canvas(self, width=width, height=height, background=self.bg)
xbar = Scrollbar(self, orient='horizontal', command=graph.xview)
ybar = Scrollbar(self, orient='vertical', command=self.yview)
graph.configure(xscrollcommand=xbar.set, yscrollcommand=ybar.set,
scrollregion=(0, 0, width, height))
scale.configure(yscrollcommand=ybar.set)
# Layout
title.grid(row=0, columnspan=3, sticky='new')
scale.grid(row=1, column=0, sticky='nsew')
graph.grid(row=1, column=1, sticky='nsew')
ybar.grid(row=1, column=2, sticky='ns')
xbar.grid(row=2, column=0, columnspan=2, sticky='ew')
self.rowconfigure(1, weight=1)
self.columnconfigure(1, weight=1)
return title, scale, graph
def addBar(self, yval):
"Add a new bar to our graph."
percent = yval / self.ymax
c = self.graph
x0 = self.xpos * self.barwidth
x1 = x0 + self.barwidth
y0 = self.gheight
y1 = (1 - percent) * self.gheight
c.create_rectangle(x0, y0, x1, y1, fill='green')
self.xpos += 1
self.updateScrollRegions()
self.graph.xview('moveto', '1.0')
def clear(self):
"Clear graph contents."
self.graph.delete('all')
self.xpos = 0
def test(self):
"Add a bar for testing purposes."
ms = 1000
if self.xpos < 10:
self.addBar(self.xpos / 10 * self.ymax)
self.after(ms, self.test)
def setTitle(self, text):
"Set graph title"
self.title.configure(text=text, font='Helvetica 9 bold')
class ConsoleApp(Frame):
"Simple Tk consoles for Mininet."
menuStyle = {'font': 'Geneva 7 bold'}
def __init__(self, net, parent=None, width=4):
Frame.__init__(self, parent)
self.top = self.winfo_toplevel()
self.gheight = 800
self.top.title('Mininet')
self.net = net
self.menubar = self.createMenuBar()
self.consoles = {}
self.sconsoles = {} # consoles themselves
titles = {
'hosts': 'Host',
'switches': 'Switch',
'controllers': 'Controller'
}
# (servers + clients) * 20
canvas = self.canvas = Canvas(self, width=1600, height=800,
scrollregion=(0, 0, 0, ((servers + nathost + clients + 200) // 4) * 280))
# cframe = self.cframe = Frame(canvas, width=1600, height=((servers + nathost + clients + 3) // 4) * 264)
cframe = self.cframe = Frame(canvas)
for name in titles:
nodes = getattr(net, name)
frame, consoles = self.createConsoles(
cframe, nodes, width, titles[name])
self.consoles[name] = Object(frame=frame, consoles=consoles)
canvas.create_window((800, ((servers + nathost + clients + 100) // 4) * 132), window=cframe)
self.selected = None
self.select('hosts')
ybar = Scrollbar(self, orient='vertical', command=canvas.yview)
canvas.config(yscrollcommand=ybar.set)
ybar.pack(side='right', fill='y')
canvas.pack(expand=True, fill='both')
cleanUpScreens()
# Close window gracefully
Wm.wm_protocol(self.top, name='WM_DELETE_WINDOW', func=self.quit)
# Initialize graph
graph = Graph(cframe)
self.consoles['graph'] = Object(frame=graph, consoles=[graph])
self.graph = graph
self.graphVisible = False
self.updates = 0
self.hostCount = len(self.consoles['hosts'].consoles)
self.bw = 0
self.pack(expand=True, fill='both')
def updateGraph(self, _console, output):
"Update our graph."
m = re.search(r'(\d+.?\d*) ([KMG]?bits)/sec', output)
if not m:
return
val, units = float(m.group(1)), m.group(2)
# convert to Gbps
if units[0] == 'M':
val *= 10 ** -3
elif units[0] == 'K':
val *= 10 ** -6
elif units[0] == 'b':
val *= 10 ** -9
self.updates += 1
self.bw += val
if self.updates >= self.hostCount:
self.graph.addBar(self.bw)
self.bw = 0
self.updates = 0
def setOutputHook(self, fn=None, consoles=None):
"Register fn as output hook [on specific consoles.]"
if consoles is None:
consoles = self.consoles['hosts'].consoles
for console in consoles:
console.outputHook = fn
def createConsoles(self, parent, nodes, width, title):
"Create a grid of consoles in a frame."
f = Frame(parent)
# Create consoles
consoles = []
index = 0
for node in nodes:
console = Console(f, self.net, node, title=title)
consoles.append(console)
row = index / width
column = index % width
console.grid(row=row, column=column, sticky='nsew')
index += 1
f.rowconfigure(row)
f.columnconfigure(column, weight=1)
return f, consoles
def select(self, groupName):
"Select a group of consoles to display."
if self.selected is not None:
self.selected.frame.pack_forget()
self.selected = self.consoles[groupName]
self.selected.frame.pack(expand=True, fill='both')
def createMenuBar(self):
"Create and return a menu (really button) bar."
f = Frame(self)
buttons = [
('Disable_watch', self.disable_watch),
('Enable_watch', self.enable_watch),
('Debug_10', self.debug_10),
('Debug_20', self.debug_20),
('Debug_40', self.debug_40),
('Debug_60', self.debug_60),
('Debug_80', self.debug_80),
('Debug_100', self.debug_100),
('Debug_150', self.debug_150),
('Debug_all', self.debug_all),
('Add_10', self.debug_Add_10),
('Reduce_10', self.debug_reduce_10),
('Stop_vland', self.stop_vland),
('Stop_watch', self.stop_watch),
('Clear', self.clear),
('Quit', self.quit)
]
for name, cmd in buttons:
b = Button(f, text=name, command=cmd, **self.menuStyle)
b.pack(side='left')
f.pack(padx=4, pady=4, fill='x')
return f
def clear(self):
"Clear selection."
for console in self.selected.consoles:
console.clear()
os.system('rm /etc/vlan_test/*/vlan.log /etc/vlan_test/*/crash.*')
def waiting(self, consoles=None):
"Are any of our hosts waiting for output?"
if consoles is None:
consoles = self.consoles['hosts'].consoles
for console in consoles:
if console.waiting():
return True
return False
def stop_vland(self):
os.system('killall vlan vland; killall -9 vlan vland')
global number
number = 0
s = 'total: ' + str(number)
print(s)
def stop_watch(self):
os.system('killall vlan; killall -9 vlan')
def disable_watch(self):
global watch
watch = 0
print('disabled watch')
def enable_watch(self):
global watch
watch = 1
print('enabled watch')
def debug_10(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 10 :
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_20(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 20:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_40(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 40:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_60(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 60:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_80(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 80:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_100(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 100:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_150(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i > number and i <= 150 :
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_all(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
i = start - 1
for console in consoles:
i += 1
if i >= number :
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_Add_10(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles):
return
global number
end = number + 10
i = start - 1
for console in consoles:
i += 1
if i > number and i <= end:
number = i
s = 'i: ' + str(i) + ' ............'
print(s)
str_i='/etc/vlan_test/' + str(i)
global watch
if watch > 0 :
console.sendCmd('nohup ' + local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid watch --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
else :
console.sendCmd('nohup ' + local_program_path + '/vland -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid --logfile=' + str_i + '/vlan.log -d 1 > /dev/null 2>&1 &')
s = 'total: ' + str(number)
print(s)
def debug_reduce_10(self):
consoles = self.consoles['hosts'].consoles
if self.waiting(consoles) or number <= 0 :
print('Already is 0')
return
global number
if number >= 10 :
end = number - 10
else :
end = 0
i = start - 1
for console in consoles:
i += 1
if i > end and i <= number:
str_i='/etc/vlan_test/' + str(i)
s = 'i: ' + str(i) + ' ............'
print(s)
result = commands.getoutput('ps -ef | grep vlan | grep -v vland | grep -v grep | grep \" /etc/vlan_test/' + str(i) + '\ " | awk \'{print $2;}\'')
for str_ in result.split() :
# print(str_)
console.sendCmd('kill ' + str_)
console.sendCmd('kill -9 ' + str_)
result = commands.getoutput('ps -ef | grep vland | grep -v grep | grep \" /etc/vlan_test/' + str(i) + '\ " | awk \'{print $2;}\'')
for str_ in result.split() :
# print(str_)
commands.getoutput(local_program_path + '/vlan -c ' + str_i + ' --pidfile=' + str_i + '/vlan.pid stop; kill ' + str_ + '; kill -9 ' + str_)
number = end
s = 'total: ' + str(number)
print(s)
# Make it easier to construct and assign objects
def assign(obj, **kwargs):
"Set a bunch of fields in an object."
obj.__dict__.update(kwargs)
class Object(object):
"Generic object you can stuff junk into."
def __init__(self, **kwargs):
assign(self, **kwargs)
if __name__ == '__main__':
import os
os.system('mn -c')
setLogLevel('info')
network = Mininet(MyTopo())
network.addNAT().configDefault()
network.start()
app = ConsoleApp(network, width=4)
# Add NAT connectivity
app.mainloop()
network.stop()