Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.6.0.3
instru_packet_trace_example.py
1 /*! \file instru_packet_trace_example.py
2  */
3 
4 #!/mnt/fastpath/usr/bin/python
5 
6 """instru_packet_trace_example.py: OpEN API Instrumentation Packet Trace example"""
7 
8 #
9 # Copyright 2016 Broadcom.
10 #
11 # Licensed under the Apache License, Version 2.0 (the "License")
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14 #
15 # http://www.apache.org/licenses/LICENSE-2.0
16 #
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22 #
23 
24 #
25 # Python 2.6.6
26 #
27 
28 # Define some constants for comparison convenience
29 
30 import OpEN_py as OpEN
31 from OpENUtil import *
32 
33 open_ = OpENUtil()
34 
35 class PacketTraceExample:
36  def __init__(self, client):
37  self.m_client = client
38 
39  def packetTraceExampleUsage(self):
40 
41  packetData_p = OpEN.new_OPEN_PT_PACKET_tp()
42  traceProfile_p = OpEN.new_OPEN_PT_TRACE_PROFILE_tp()
43  time_p = OpEN.new_time_tp()
44  asic = 0;
45  port = 1234;
46 
47  result = OpEN.openapiPtTraceProfileGet(self.m_client, asic, port, packetData_p, traceProfile_p, time_p)
48  if result == OpEN.OPEN_E_NONE:
49  print "Success to get trace profile."
50  else:
51  print "Bad return code trying to get trace profile. result = %d" % (result)
52 
53  OpEN.delete_OPEN_PT_PACKET_tp(packetData_p)
54  OpEN.delete_OPEN_PT_TRACE_PROFILE_tp(traceProfile_p)
55  OpEN.delete_time_tp(time_p)
56 
57 
58 def main():
59  """Demonstrate OpEN usage for Packet Trace APIs"""
60 
61  open = OpENUtil()
62  ret = open.connect("instru_packet_trace_example")
63  if ret == OpEN.OPEN_E_NONE :
64  open.getNetworkOSVersion()
65  open.getAPIVersion()
66  client = open.get_client()
67  packetTraceExample = PacketTraceExample(client)
68  packetTraceExample.packetTraceExampleUsage()
69  open.terminate()
70  else:
71  print "Unable to connect"
72 
73 if __name__ == '__main__': main()
74