aboutsummaryrefslogtreecommitdiffstats
path: root/tools/docker/client/vsperf_client.py
blob: 2a3e509f17e2e460631bfe518e85f5ba6f1bdee5 (plain)
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
"""Deploy : vsperf_deploy_client"""
#pylint: disable=import-error

import configparser
import sys
from pathlib import Path


import grpc
from proto import vsperf_pb2
from proto import vsperf_pb2_grpc

CHUNK_SIZE = 1024 * 1024  # 1MB


HEADER = r"""
 _  _  ___  ____  ____  ____  ____     ___  __    ____  ____  _  _  ____
( \/ )/ __)(  _ \( ___)(  _ \( ___)   / __)(  )  (_  _)( ___)( \( )(_  _)
 \  / \__ \ )___/ )__)  )   / )__)   ( (__  )(__  _)(_  )__)  )  (   )(
  \/  (___/(__)  (____)(_)\_)(__)     \___)(____)(____)(____)(_)\_) (__)
"""

COLORS = {
    'blue': '\033[94m',
    'pink': '\033[95m',
    'green': '\033[92m',
}

DUT_CHECK = 0
TGEN_CHECK = 0

def colorize(string, color):
    """Colorized HEADER"""
    if color not in COLORS:
        return string
    return COLORS[color] + string + '\033[0m'


class VsperfClient():
    """
    This class reprsents the VSPERF-client.
    It talks to vsperf-docker to perform installation, configuration and
    test-execution
    """
    # pylint: disable=R0904,no-else-break
    # pylint: disable=W0603,invalid-name
    # pylint: disable=R1710
    def __init__(self):
        """read vsperfclient.conf"""
        self.cfp = 'vsperfclient.conf'
        self.config = configparser.RawConfigParser()
        self.config.read(self.cfp)
        self.stub = None
        self.dut_check = 0
        self.tgen_check = 0
    
    def get_mode(self):
    	"""read the mode for the client"""
    	return self.config.get('Mode', 'mode')

    def get_deploy_channel_info(self):
        """get the channel data"""
        return (self.config.get('DeployServer', 'ip'),
                self.config.get('DeployServer', 'port'))

    def get_test_channel_info(self):
        """get the channel for tgen"""
        return (self.config.get('TestServer', 'ip'),
                self.config.get('TestServer', 'port'))

    def create_stub(self, channel):
        """create stub to talk to controller"""
        self.stub = vsperf_pb2_grpc.ControllerStub(channel)
    
    def host_connect(self):
        """provice dut-host credential to controller"""
        global DUT_CHECK
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        connect_reply = self.stub.HostConnect(hostinfo)
        DUT_CHECK = 1
        print(connect_reply.message)

    def tgen_connect(self):
        """provide tgen-host credential to controller"""
        global TGEN_CHECK
        tgeninfo = vsperf_pb2.HostInfo(ip=self.config.get('TGen', 'ip'),
                                       uname=self.config.get('TGen', 'uname'),
                                       pwd=self.config.get('TGen', 'pwd'))
        connect_reply = self.stub.TGenHostConnect(tgeninfo)
        TGEN_CHECK = 1
        print(connect_reply.message)

    def host_connect_both(self):
        """provice dut-host credential to controller"""
        global DUT_CHECK
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        connect_reply = self.stub.HostConnect(hostinfo)
        client = VsperfClient()
        client.automatically_test_dut_connect()
        DUT_CHECK = 1
        print(connect_reply.message)

    def tgen_connect_both(self):
        """provide tgen-host credential to controller"""
        global TGEN_CHECK
        tgeninfo = vsperf_pb2.HostInfo(ip=self.config.get('TGen', 'ip'),
                                       uname=self.config.get('TGen', 'uname'),
                                       pwd=self.config.get('TGen', 'pwd'))
        connect_reply = self.stub.TGenHostConnect(tgeninfo)
        TGEN_CHECK = 1
        client = VsperfClient()
        client.automatically_test_tgen_connect()
        print(connect_reply.message)

    @classmethod
    def automatically_test_dut_connect(cls):
        """handle automatic connection with tgen"""
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        channel = grpc.insecure_channel(ip_add + ':' + port)
        client.create_stub(channel)
        client.host_testcontrol_connect()

    @classmethod
    def automatically_test_tgen_connect(cls):
        """handle automatic connection with tgen"""
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        channel = grpc.insecure_channel(ip_add + ':' + port)
        client.create_stub(channel)
        client.tgen_testcontrol_connect()

    def exit_section(self):
        """exit"""
    @classmethod
    def section_execute(cls, menuitems, client, ip_add, port):
        """it will use to enter into sub-option"""
        channel = grpc.insecure_channel(ip_add + ':' + port)

        while True:
            client.create_stub(channel)
            while True:
                # os.system('clear')
                print(colorize(HEADER, 'blue'))
                print(colorize('version 0.1\n', 'pink'))
                for item in menuitems:
                    print(colorize("[" +
                                   str(menuitems.index(item)) + "]", 'green') +
                          list(item.keys())[0])
                choice = input(">> ")
                try:
                    if int(choice) < 0:
                        raise ValueError
                    if (int(choice) >= 0) and (int(choice) < (len(menuitems) - 1)):
                        list(menuitems[int(choice)].values())[0]()
                    else:
                        break
                except (ValueError, IndexError):
                    pass
            break
    @classmethod
    def get_user_trex_conf_location(cls):
        """Ask user for t-rex configuration location"""
        while True:
            filename_1 = str(input("Provide correct location for your t-rex configuration " \
                                     "file where trex_cfg.yaml exist\n" \
                                     "***************** Make Sure You Choose Correct" \
                                     " File for Upload*******************\n" \
                                     "Provide location: \n"))
            user_file = Path("{}".format(filename_1.strip()))
            if user_file.is_file():
                break
            else:
                print("**************File Does Not Exist*****************\n")
                continue
        return filename_1

    def upload_tgen_config(self):
        """t-rex config file as a chunk to controller"""
        if TGEN_CHECK == 0:
            return print("TGen-Host is not Connected [!]" \
                         "\nMake sure to establish connection with TGen-Host.")
        default_location = self.config.get('ConfFile', 'tgenpath')
        if not default_location:
            filename = self.get_user_trex_conf_location()
        else:
            user_preference = str(input("Use location specified in vsperfclient.conf?[Y/N] :"))
            while True:
                if 'y' in user_preference.lower().strip():
                    filename = self.config.get('ConfFile', 'tgenpath')
                    user_file = Path("{}".format(filename.strip()))
                    if user_file.is_file():
                        break
                    else:
                        print("**************File Does Not Exist*****************\n")
                        user_preference = 'n'
                        continue
                elif 'n' in user_preference.lower().strip():
                    filename = self.get_user_trex_conf_location()
                    break
                else:
                    print("Invalid Input")
                    user_preference = str(input("Use location specified in vsperfclient.conf?" \
                                                "[Y/N] : "))
                    continue
        filename = filename.strip()
        chunks = self.get_file_chunks_1(filename)
        upload_status = self.stub.TGenUploadConfigFile(chunks)
        print(upload_status.Message)

    def vsperf_install(self):
        """vsperf install on dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        install_reply = self.stub.VsperfInstall(hostinfo)
        print(install_reply.message)

    def collectd_install(self):
        """collectd install on dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        install_reply = self.stub.CollectdInstall(hostinfo)
        print(install_reply.message)

    def tgen_install(self):
        """install t-rex on Tgen host"""
        tgeninfo = vsperf_pb2.HostInfo(ip=self.config.get('TGen', 'ip'),
                                       uname=self.config.get('TGen', 'uname'),
                                       pwd=self.config.get('TGen', 'pwd'))
        install_reply = self.stub.TGenInstall(tgeninfo)
        print(install_reply.message)

    @classmethod
    def get_user_conf_location(cls):
        """get user input for test configuration file"""
        while True:
            filename_1 = str(input("Provide correct location for your test configuration " \
                                     "file where it exist\n" \
                                     "***************** Make Sure You Choose Correct" \
                                     " Test File for Upload*******************\n" \
                                     "Provide location: \n"))
            user_file = Path("{}".format(filename_1.strip()))
            if user_file.is_file():
                break
            else:
                print("**************File Does Not Exist*****************\n")
                continue
        return filename_1

    def upload_config(self):
        """transfer config file as a chunk to controller"""
        if DUT_CHECK == 0:
            return print("DUT-Host is not Connected [!]" \
                         "\nMake sure to establish connection with DUT-Host.")
        default_location = self.config.get('ConfFile', 'path')
        if not default_location:
            filename = self.get_user_conf_location()
        else:
            user_preference = str(input("Use location specified in vsperfclient.conf?[Y/N] :"))
            while True:
                if 'y' in user_preference.lower().strip():
                    filename = self.config.get('ConfFile', 'path')
                    user_file = Path("{}".format(filename.strip()))
                    if user_file.is_file():
                        break
                    else:
                        print("**************File Does Not Exist*****************\n")
                        user_preference = 'n'
                        continue
                elif 'n' in user_preference.lower().strip():
                    filename = self.get_user_conf_location()
                    break
                else:
                    print("Invalid Input")
                    user_preference = str(input("Use location specified in vsperfclient.conf?" \
                                                "[Y/N] : "))
                    continue
        filename = filename.strip()
        upload_param = self.get_file_chunks(filename)
        upload_status = self.stub.UploadConfigFile(upload_param)
        print(upload_status.Message)

    def start_test(self):
        """start test parameter, test config file and test name"""
        test_control = vsperf_pb2.ControlVsperf(testtype=self.config.get('Testcase', 'test'), \
                                                conffile=self.config.get('Testcase', 'conffile'))
        control_reply = self.stub.StartTest(test_control)
        print(control_reply.message)

    def start_tgen(self):
        """start t-rex traffic generetor on tgen-host"""
        tgen_control = vsperf_pb2.ControlTGen(params=self.config.get('TGen', 'params'))
        control_reply = self.stub.StartTGen(tgen_control)
        print(control_reply.message)

    @classmethod
    def get_file_chunks(cls, filename):
        """convert file into chunk to stream between client and controller with filename"""
        with open(filename, 'rb') as f_1:
            while True:
                file_path = filename
                file_path_list = file_path.split("/")
                test_filename = file_path_list[(len(file_path_list)-1)]
                piece = f_1.read(CHUNK_SIZE)
                if not piece:
                    return None
                return vsperf_pb2.ConfFileTest(Content=piece, Filename=test_filename)
    @classmethod
    def get_file_chunks_1(cls, filename):
        """Convert file into chunks"""
        with open(filename, 'rb') as f:
            while True:
                piece = f.read(CHUNK_SIZE)
                if len(piece) == 0:
                    return
                yield vsperf_pb2.ConfFile(Content=piece)


    def test_status(self):
        """check the test_status"""
        test_check = vsperf_pb2.StatusQuery(
            testtype=self.config.get('Testcase', 'test'))
        check_result_reply = self.stub.TestStatus(test_check)
        print(check_result_reply.message)

    def vsperf_terminate(self):
        """after running test terminate vsperf on dut host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        termination_reply = self.stub.TerminateVsperf(hostinfo)
        print(termination_reply.message)

    def start_beats(self):
        """start beats on dut-host before running test"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.StartBeats(hostinfo)
        print(status_reply.message)

    def remove_vsperf(self):
        """remove vsperf from dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.RemoveVsperf(hostinfo)
        print(status_reply.message)

    def remove_result_folder(self):
        """remove resutl folder from dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.RemoveResultFolder(hostinfo)
        print(status_reply.message)

    def remove_config_files(self):
        """remove all config files"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.RemoveUploadedConfig(hostinfo)
        print(status_reply.message)

    def remove_collectd(self):
        """remove collectd from dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.RemoveCollectd(hostinfo)
        print(status_reply.message)

    def remove_everything(self):
        """remove everything from dut host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.RemoveEverything(hostinfo)
        print(status_reply.message)

    def sanity_nic_check(self):
        """nic is available on tgen host check"""
        tgeninfo = vsperf_pb2.HostInfo(ip=self.config.get('TGen', 'ip'),
                                       uname=self.config.get('TGen', 'uname'),
                                       pwd=self.config.get('TGen', 'pwd'))
        status_reply = self.stub.SanityNICCheck(tgeninfo)
        print(status_reply.message)

    def sanity_collectd_check(self):
        """check collecd properly running"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.SanityCollectdCheck(hostinfo)
        print(status_reply.message)

    def cpu_allocation_check(self):
        """check cpu allocation"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.SanityCPUAllocationCheck(hostinfo)
        print(status_reply.message)

    def sanity_vnf_path(self):
        """vnf path available on dut host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.SanityVNFpath(hostinfo)
        print(status_reply.message)

    def sanity_vsperf_check(self):
        """check vsperf correctly installed"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.SanityVSPERFCheck(hostinfo)
        print(status_reply.message)

    def sanity_dut_tgen_conn_check(self):
        """check the connection between dut-host and tgen-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.SanityTgenConnDUTCheck(hostinfo)
        print(status_reply.message)

    def dut_test_availability(self):
        """dut-host is free for test check"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.DUTvsperfTestAvailability(hostinfo)
        print(status_reply.message)

    def get_test_conf_from_dut(self):
        """get the vsperf test config file from dut host for user to check"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        status_reply = self.stub.GetVSPERFConffromDUT(hostinfo)
        print(status_reply.message)

    def dut_hugepage_config(self):
        """setup hugepages on dut-host"""
        configparam = vsperf_pb2.HugepConf(hpmax=self.config.get('HugepageConfig', 'HpMax'), \
                                           hprequested=self.config.get('HugepageConfig',\
                                            'HpRequested'))
        config_status_reply = self.stub.DutHugepageConfig(configparam)
        print(config_status_reply.message)
    @classmethod
    def get_user_collectd_conf_location(cls):
        """get collectd configuration file location from user"""
        while True:
            filename_1 = str(input("Provide correct location for your collectd configuration " \
                                     "file where collectd.conf exist\n" \
                                     "***************** Make Sure You Choose Correct" \
                                     " File for Upload*******************\n" \
                                     "Provide location: \n"))
            user_file = Path("{}".format(filename_1.strip()))
            if user_file.is_file():
                break
            else:
                print("**************File Does Not Exist*****************\n")
                continue
        return filename_1
    def host_testcontrol_connect(self):
        """provice dut-host credential to test controller"""
        global DUT_CHECK
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        self.stub.HostConnect(hostinfo)

    def tgen_testcontrol_connect(self):
        """provide tgen-host credential to test controller"""
        global TGEN_CHECK
        tgeninfo = vsperf_pb2.HostInfo(ip=self.config.get('TGen', 'ip'),
                                       uname=self.config.get('TGen', 'uname'),
                                       pwd=self.config.get('TGen', 'pwd'))
        self.stub.TGenHostConnect(tgeninfo)

    def upload_collectd_config(self):
        """collectd config file chunks forwarded to controller"""
        if DUT_CHECK == 0:
            return print("DUT-Host is not Connected [!]" \
                         "\nMake sure to establish connection with DUT-Host.")
        default_location = self.config.get('ConfFile', 'collectdpath')
        if not default_location:
            filename = self.get_user_collectd_conf_location()
        else:
            user_preference = str(input("Use location specified in vsperfclient.conf?[Y/N] :"))
            while True:
                if 'y' in user_preference.lower().strip():
                    filename = self.config.get('ConfFile', 'collectdpath')
                    user_file = Path("{}".format(filename.strip()))
                    if user_file.is_file():
                        break
                    else:
                        print("**************File Does Not Exist*****************\n")
                        user_preference = 'n'
                        continue
                elif 'n' in user_preference.lower().strip():
                    filename = self.get_user_collectd_conf_location()
                    break
                else:
                    print("Invalid Input")
                    user_preference = str(input("Use location specified in vsperfclient.conf?" \
                                                "[Y/N] : "))
                    continue
        filename = filename.strip()
        chunks = self.get_file_chunks_1(filename)
        upload_status = self.stub.CollectdUploadConfig(chunks)
        print(upload_status.Message)

    def dut_check_dependecies(self):
        """check_dependecies on dut-host"""
        hostinfo = vsperf_pb2.HostInfo(ip=self.config.get('Host', 'ip'),
                                       uname=self.config.get('Host', 'uname'),
                                       pwd=self.config.get('Host', 'pwd'))
        check_reply = self.stub.CheckDependecies(hostinfo)
        print(check_reply.message)
    
    @classmethod
    def establish_connection_both(cls):
        """
        This Function use to establish connection for vsperf to both the deploy server \
        and testcontrol server
        """
        client = VsperfClient()
        ip_add, port = client.get_deploy_channel_info()
        print("Establish connection for vsperf")
        menuitems_connection = [
            {"Connect to DUT Host": client.host_connect_both},
            {"Connect to TGen Host": client.tgen_connect_both},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_connection, client, ip_add, port)
    @classmethod
    def establish_connection_deploy(cls):
        """
        This Function use to establish connection for vsperf to either using the dploy 
        or using the testcontrol server
        """
        client = VsperfClient()
        ip_add, port = client.get_deploy_channel_info()
        print("Establish connection for vsperf")
        menuitems_connection = [
            {"Connect to DUT Host": client.host_connect},
            {"Connect to TGen Host": client.tgen_connect},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_connection, client, ip_add, port)
    @classmethod
    def establish_connection_test(cls):
        """
        This Function use to establish connection for vsperf to either using the dploy 
        or using the testcontrol server
        """
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        print("Establish connection for vsperf")
        menuitems_connection = [
            {"Connect to DUT Host": client.host_connect},
            {"Connect to TGen Host": client.tgen_connect},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_connection, client, ip_add, port)
    @classmethod
    def vsperf_setup(cls):
        """setup sub-options"""
        client = VsperfClient()
        ip_add, port = client.get_deploy_channel_info()
        print("Prerequisites Installation for VSPERF")
        menuitems_setup = [
            {"Install VSPERF": client.vsperf_install},
            {"Install TGen ": client.tgen_install},
            {"Install Collectd": client.collectd_install},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)
    @classmethod
    def upload_config_files(cls):
        """all the upload sub-options"""
        client = VsperfClient()
        ip_add, port = client.get_deploy_channel_info()
        menuitems_setup = [
            {"Upload TGen Configuration File": client.upload_tgen_config},
            {"Upload Collectd Configuration File": client.upload_collectd_config},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)
    @classmethod
    def manage_sysparam_config(cls):
        """manage system parameter on dut host before run test"""
        client = VsperfClient()
        ip_add, port = client.get_deploy_channel_info()
        menuitems_setup = [
            {"DUT-Host hugepages configuration": client.dut_hugepage_config},
            {"Check VSPERF Dependencies on DUT-Host": client.dut_check_dependecies},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)

    @classmethod
    def test_status_check(cls):
        """after running test , test status related sub-options"""
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        menuitems_setup = [
            {"Test status": client.test_status},
            {"Get Test Configuration file from DUT-host": client.get_test_conf_from_dut},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)

    @classmethod
    def sanity_check_options(cls):
        """all sanity check sub-options"""
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        menuitems_setup = [
            {"Check installed VSPERF": client.sanity_vsperf_check},
            {"Check Test Config's VNF path is available on DUT-Host": client.sanity_vnf_path},
            {"Check NIC PCIs is available on Traffic Generator": client.sanity_nic_check},
            {"Check CPU allocation on DUT-Host": client.cpu_allocation_check},
            {"Check installed Collectd": client.sanity_collectd_check},
            {"Check Connection between DUT-Host and Traffic Generator Host":
             client.sanity_dut_tgen_conn_check},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)

    @classmethod
    def run_test(cls):
        """run test sub-options"""
        print("**Before user Run Tests we highly recommend user to perform Sanity Checks.......")
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        menuitems_setup = [
            {"Upload Test Configuration File": client.upload_config},
            {"Perform Sanity Checks before running tests": client.sanity_check_options},
            {"Check if DUT-HOST is available": client.dut_test_availability},
            {"Start TGen ": client.start_tgen},
            {"Start Beats": client.start_beats},
            {"Start Test": client.start_test},
            {"Return to Previous Menu": client.exit_section}
        ]
        client.section_execute(menuitems_setup, client, ip_add, port)

    @classmethod
    def clean_up(cls):
        """clean-up sub-options"""
        print(
            "*******************************************************************\n\n\
             IF you are performing Test on IntelPOD 12 - Node 4, Be careful during removal\n\n\
             *******************************************************************")
        client = VsperfClient()
        ip_add, port = client.get_test_channel_info()
        menuitems_setup = [
            {"Remove VSPERF": client.remove_vsperf},
            {"Terminate VSPERF": client.vsperf_terminate},
            {"Remove Results from DUT-Host": client.remove_result_folder},
            {"Remove Uploaded Configuration File": client.remove_config_files},
            {"Remove Collectd": client.remove_collectd},
            {"Remove Everything": client.remove_everything},
            {"Return to Previous Menu": client.exit_section}

        ]
        client.section_execute(menuitems_setup, client, ip_add, port)

def run():
    """It will run the actul primary options"""
    client = VsperfClient()
    client_mode = client.get_mode()
    print(client_mode)
    if "deploy" in client_mode.lower().strip():
        menuitems = [
        {"Establish Connections": client.establish_connection_deploy},
        {"Installation": client.vsperf_setup},
        {"Upload Configuration Files": client.upload_config_files},
        {"Manage DUT-System Configuration": client.manage_sysparam_config},
        {"Exit": sys.exit}
        ]
        #ip_add, port = client.get_channel_info()
        #channel = grpc.insecure_channel(ip_add + ':' + port)
        while True:
        # os.system('clear')
            print(colorize(HEADER, 'blue'))
            print(colorize('version 0.1\n', 'pink'))
            for item in menuitems:
                print(colorize("[" +
                               str(menuitems.index(item)) + "]", 'green') +
                      list(item.keys())[0])
            choice = input(">> ")
            try:
                if int(choice) < 0:
                    raise ValueError
                list(menuitems[int(choice)].values())[0]()
            except (ValueError, IndexError):
                pass

    elif "test" in  client_mode.lower().strip():
        menuitems = [
        {"Establish Connections": client.establish_connection_test},
        {"Run Test": client.run_test},
        {"Test Status": client.test_status_check},
        {"Clean-Up": client.clean_up},
        {"Exit": sys.exit}
	    ]
        #ip_add, port = client.get_channel_info()
        #channel = grpc.insecure_channel(ip_add + ':' + port)
        while True:
            # os.system('clear')
            print(colorize(HEADER, 'blue'))
            print(colorize('version 0.1\n', 'pink'))
            for item in menuitems:
                print(colorize("[" +
                               str(menuitems.index(item)) + "]", 'green') +
                      list(item.keys())[0])
            choice = input(">> ")
            try:
                if int(choice) < 0:
                    raise ValueError
                list(menuitems[int(choice)].values())[0]()
            except (ValueError, IndexError):
                pass

    elif "together" in client_mode.lower().strip():
        menuitems = [
        {"Establish Connections": client.establish_connection_both},
        {"Installation": client.vsperf_setup},
        {"Upload Configuration Files": client.upload_config_files},
        {"Manage DUT-System Configuration": client.manage_sysparam_config},
        {"Run Test": client.run_test},
        {"Test Status": client.test_status_check},
        {"Clean-Up": client.clean_up},
        {"Exit": sys.exit}
	    ]
        #ip_add, port = client.get_channel_info()
        #channel = grpc.insecure_channel(ip_add + ':' + port)
        while True:
            # os.system('clear')
            print(colorize(HEADER, 'blue'))
            print(colorize('version 0.1\n', 'pink'))
            for item in menuitems:
                print(colorize("[" +
                               str(menuitems.index(item)) + "]", 'green') +
                      list(item.keys())[0])
            choice = input(">> ")
            try:
                if int(choice) < 0:
                    raise ValueError
                list(menuitems[int(choice)].values())[0]()
            except (ValueError, IndexError):
                pass

    else:
        print("You have not defined client mode in vsperfclient.conf [!]")


if __name__ == '__main__':
    run()