JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / agent / spirent / spirent.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 import Tkinter
12
13
14 def build_cmd(*args):
15     cmd = ''
16     for arg in args:
17         cmd = cmd+str(arg)+' '
18     #import pdb
19     #pdb.set_trace()
20     return cmd
21
22
23 class stcPython():
24     def __init__(self):
25         self.tclsh = Tkinter.Tcl()
26         self.stcpkg = '/home/Spirent_TestCenter_4.46/Spirent_TestCenter_Application_Linux'
27         self.tclsh.eval("set auto_path [ linsert $auto_path 0 %s ]" %(self.stcpkg))
28         self.tclsh.eval("package require SpirentTestCenter")
29
30     def build_cmd(self, *args):
31         cmd = ''
32         for arg in args:
33             cmd = cmd+str(arg)+' '
34         return cmd
35
36     # [ stc base interface ]
37     def stc_init(self, *args):
38         cmd = build_cmd('stc::init', *args)
39         return self.tclsh.eval(cmd)
40     # stc connect
41     def stc_connect(self,*args):
42         cmd = build_cmd('stc::connect', *args)
43         return self.tclsh.eval(cmd)
44     # stc disconnect
45     def stc_disconnect(self,*args):
46         cmd = build_cmd('stc::disconnect', *args)
47         return self.tclsh.eval(cmd)
48     # stc create
49     def stc_create(self,*args):
50         cmd = build_cmd('stc::create', *args)
51         return self.tclsh.eval(cmd)
52     # stc delete
53     def stc_delete(self,*args):
54         cmd = build_cmd('stc::delete', *args)
55         return self.tclsh.eval(cmd)
56     # stc config
57     def stc_config(self,*args):
58         cmd = build_cmd('stc::config', *args)
59         return self.tclsh.eval(cmd)
60     # stc get
61     def stc_get(self,*args):
62         cmd = build_cmd('stc::get', *args)
63         return self.tclsh.eval(cmd)
64     # stc apply
65     def stc_apply(self,*args):
66         cmd = build_cmd('stc::apply', *args)
67         return self.tclsh.eval(cmd)
68     # stc perform
69     def stc_perform(self,*args):
70         cmd = build_cmd('stc::perform', *args)
71         return self.tclsh.eval(cmd)
72     # stc reserve
73     def stc_reserve(self,*args):
74         cmd = build_cmd('stc::reserve', *args)
75         return self.tclsh.eval(cmd)
76     # stc release
77     def stc_release(self,*args):
78         cmd = build_cmd('stc::release', *args)
79         return self.tclsh.eval(cmd)
80     # stc subscribe
81     def stc_subscribe(self,*args):
82         cmd = build_cmd('stc::subscribe',*args)
83         return self.tclsh.eval(cmd)
84     # stc unsubscribe
85     def stc_unsubscribe(self,*args):
86         cmd = build_cmd('stc::unsubscribe', *args)
87         return self.tclsh.eval(cmd)
88     # stc wait until sequencer complete
89     def stc_waituntilcomplete(self,*args):
90         cmd = build_cmd('stc::waituntilcomplete', *args)
91         return self.tclsh.eval(cmd)
92     # stc help
93     def stc_help(self, *args):
94         cmd = build_cmd('stc::help',*args)
95         return self.tclsh.eval(cmd)
96
97     # [ stc expand interface ]
98     # get one dict-key's value
99     # return value
100     def stc_get_value(self,stc_dict,stc_key):
101         cmd = stc_dict+' -'+stc_key
102         return self.stc_get(cmd)
103     # create project
104     # return: project_name
105     def stc_create_project(self):
106         return self.stc_create('project')
107     # create port under project
108     # return: port name
109     def stc_create_port(self,project_name):
110         cmd = 'port -under '+project_name
111         return self.stc_create(cmd)
112     # config port location
113     # return: None
114     def stc_config_port_location(self,port_name,chassisAddress,slot,port):
115         #import pdb
116         #pdb.set_trace()
117         cmd = port_name+' -location //'+chassisAddress+'/'+slot+'/'+port+' -UseDefaultHost False'
118         return self.stc_config(cmd)
119     # create streamblock under port
120     # return: streamblock name
121     def stc_create_streamblock(self,port_name,vlan_tag,ExpectedRxPort,srcMac,dstMac,sourceAddr,destAddr):
122         #import pdb
123         #pdb.set_trace()
124         if vlan_tag == None or vlan_tag == 'None':
125             frameStruc = '"EthernetII IPv4 Udp"'
126             if ExpectedRxPort == '' :
127                 return self.stc_create( 'streamBlock -under ',port_name,
128                                         '-frameConfig ',frameStruc,
129                                         '-frame "EthernetII.srcMac',srcMac,'EthernetII.dstMac',dstMac,
130                                         'IPv4.1.sourceAddr',sourceAddr,'IPv4.1.destAddr',destAddr,'"')
131             else :
132                 return self.stc_create( 'streamBlock -under ',port_name,
133                                         '-ExpectedRxPort',ExpectedRxPort,
134                                         '-frameConfig ',frameStruc,
135                                         '-frame "EthernetII.srcMac',srcMac,'EthernetII.dstMac',dstMac,
136                                         'IPv4.1.sourceAddr',sourceAddr,'IPv4.1.destAddr',destAddr,'"')
137         else :
138             frameStruc = '"EthernetII Vlan IPv4 Udp"'
139             if ExpectedRxPort == '' :
140                 return self.stc_create( 'streamBlock -under ',port_name,
141                                         '-frameConfig '+frameStruc,
142                                         '-frame "EthernetII.srcMac',srcMac,'EthernetII.dstMac',dstMac,
143                                         'Vlan.1.id',vlan_tag,
144                                         'IPv4.1.sourceAddr',sourceAddr,'IPv4.1.destAddr',destAddr,'"')
145             else :
146                 return self.stc_create( 'streamBlock -under ',port_name,
147                                         '-ExpectedRxPort',ExpectedRxPort,
148                                         '-frameConfig '+frameStruc,
149                                         '-frame "EthernetII.srcMac',srcMac,'EthernetII.dstMac',dstMac,
150                                         'Vlan.1.id',vlan_tag,
151                                         'IPv4.1.sourceAddr',sourceAddr,'IPv4.1.destAddr',destAddr,'"')
152     # config streamblock with part arguments
153     # argument list use args dictionary
154     def stc_config_streamblock(self,streamblock_name,args_dict):
155         cmd = ''
156         for key in args_dict.keys() :
157             temp_cmd = '-'+key+' '+str(args_dict[key])
158             cmd = cmd + temp_cmd
159         return self.stc_config(streamblock_name,cmd)
160     # get generator name from port name
161     # return: generator name
162     def stc_get_generator(self,port_name):
163         cmd = port_name+' -children-generator'
164         return self.stc_get(cmd)
165     # config generator with part arguments
166     # argument list use args dictionary
167     # return none
168     def stc_config_generator(self,generator_name,args_dict):
169         cmd = ''
170         for key in args_dict.keys() :
171             temp_cmd = '-'+key+' '+str(args_dict[key])
172             cmd = cmd + temp_cmd
173         return self.stc_config(generator_name,cmd)
174     # attach port
175     # return: port's parent project info
176     def stc_attach_ports(self,portList):
177         cmd = 'AttachPorts -portList {'
178         for port in portList :
179             cmd = cmd+' '+port
180         cmd = cmd+'} -autoConnect TRUE'
181         return self.stc_perform(cmd)
182     # config src mac and dst mac
183     # return: none
184     def stc_config_ethII(self,ethII,src_mac,dst_mac):
185         cmd = ethII+' -srcMac '+src_mac+' -dstMac '+dst_mac
186         return self.stc_config(cmd)
187     # config src ip and dst ip
188     # return: none
189     def stc_config_ethIII(self,ethIII,src_ip,dst_ip):
190         cmd = ethIII+' -sourceAddr '+src_ip+' -destAddr '+dst_ip
191         return self.stc_config(cmd)
192     # start streamblock
193     # return: none
194     def stc_streamblock_start(self,streamblock_list):
195         cmd = 'StreamBlockStart -StreamBlockList {'
196         for streamblock in streamblock_list :
197             cmd = cmd+' '+streamblock
198         cmd = cmd+' } -ExecuteSynchronous TRUE'
199         return self.stc_perform(cmd)
200     # stop streamblock
201     def stc_streamblock_stop(self,streamblock_list):
202         cmd = 'StreamBlockStop -StreamBlockList {'
203         for streamblock in streamblock_list :
204             cmd = cmd+' '+streamblock
205         cmd = cmd+' } -ExecuteSynchronous TRUE'
206         return self.stc_perform(cmd)
207     # start generator
208     # return: none
209     def stc_generator_start(self,generator_List):
210         cmd = 'GeneratorStart -generatorList {'
211         for generator in generator_List :
212             cmd = cmd+' '+generator
213         cmd = cmd+' }'
214         return self.stc_perform(cmd)
215     # stop generator
216     # return: none
217     def stc_generator_stop(self,generator_List):
218         cmd = 'GeneratorStop -generatorList {'
219         for generator in generator_List :
220             cmd = cmd+' '+generator
221         cmd = cmd+' }'
222         return self.stc_perform(cmd)
223     # create rfc2544 throughput test
224     def stc_setup_rfc2544_throughput(self):
225         pass
226     # create rfc2544 frameloss test
227     def stc_setup_rfc2544_frameloss(self):
228         pass
229     # create rfc2544 latency test
230     def stc_setup_rfc2544_latency(self):
231         pass
232     # start Sequence start
233     def stc_sequence_start(self):
234         return self.stc_perform('SequencerStart')
235     # output rfc2544 throughput result
236     def stc_get_rfc2544_throughput_result(self):
237         pass
238     # output rfc2544 frameloss result
239     def stc_get_rfc2544_frameloss_result(self):
240         pass
241     # output rfc2544 latency result
242     def stc_get_rfc2544_latency_result(self):
243         pass