1 /*! \file instru_example.py
6 """instru_example.py: OpEN API Instrumentation BST example"""
35 def print_sanity_results(result, test, msg, feat):
36 """Print overall comparision results"""
38 if result == OpEN.OPEN_E_UNAVAIL:
39 print "Sanity test skipped."
40 elif result == OpEN.OPEN_E_NONE
and test ==
True:
41 print "Sanity Success - %s - %s." % (msg, feat)
43 print "Sanity Failure - %s - %s." % (msg, feat)
45 def print_bad_result(result, msg):
46 """Print some general error messages if the result is bad"""
48 if result == OpEN.OPEN_E_UNAVAIL:
49 print "Feature not supported - %s (err %d)." % (msg, result)
50 elif result != OpEN.OPEN_E_NONE:
51 print "Test Failure - %s (err %d)." % (msg, result)
54 """Simple Instru Examples """
56 def __init__(self, client, asic) :
57 self.m_client = client
69 def show_asic_capability(self):
70 asic_cap_p = OpEN.new_OPEN_ASIC_CAPABILITIES_tp()
71 result=OpEN.openapiBstAsicCapabilityGet(self.m_client, self.m_asic, asic_cap_p)
72 if (result != OpEN.OPEN_E_NONE):
73 print "Error ! failed to get asic capability"
74 OpEN.delete_OPEN_ASIC_CAPABILITIES_tp(asic_cap_p)
77 asic_cap = OpEN.OPEN_ASIC_CAPABILITIES_tp_value(asic_cap_p)
78 print "Asic Capability"
79 print "==============================================="
80 print "Asic numPorts - %d" % (asic_cap.numPorts)
81 print "Asic numUnicastQueues - %d" % (asic_cap.numUnicastQueues)
82 print "Asic numUnicastQueueGroups - %d" % (asic_cap.numUnicastQueueGroups)
83 print "Asic numMulticastQueues - %d" % (asic_cap.numMulticastQueues)
84 print "Asic numServicePools - %d" % (asic_cap.numServicePools)
85 print "Asic numCommonPools - %d" % (asic_cap.numCommonPools)
86 print "Asic numCpuQueues - %d" % (asic_cap.numCpuQueues)
87 print "Asic numRqeQueues - %d" % (asic_cap.numRqeQueues)
88 print "Asic numRqeQueuePools - %d" % (asic_cap.numRqeQueuePools)
89 print "Asic numPriorityGroups - %d" % (asic_cap.numPriorityGroups)
91 self.m_ports = asic_cap.numPorts
92 self.m_ucq = asic_cap.numUnicastQueues
93 self.m_ucqg = asic_cap.numUnicastQueueGroups
94 self.m_mcq = asic_cap.numMulticastQueues
95 self.m_cpuq = asic_cap.numCpuQueues
96 self.m_rqe = asic_cap.numRqeQueues
97 self.m_spool = asic_cap.numServicePools
98 self.m_pg = asic_cap.numPriorityGroups
100 OpEN.delete_OPEN_ASIC_CAPABILITIES_tp(asic_cap_p)
102 def config_ipsp_threshold(self, spool, port, thre):
104 print "Setting IPSP Threshold"
105 print "========================================="
106 ipspThre_p = OpEN.new_OPEN_BST_INGRESS_PORT_SP_THRESHOLD_tp()
107 ipspThre = OpEN.OPEN_BST_INGRESS_PORT_SP_THRESHOLD_tp_value(ipspThre_p)
109 ipspThre.umShareThreshold = thre;
111 print "Setting threshold %d for service pool %d , port %d" % (thre, spool, port)
113 OpEN.OPEN_BST_INGRESS_PORT_SP_THRESHOLD_tp_assign(ipspThre_p, ipspThre)
114 result=OpEN.openapiBstIpspThresholdSet(self.m_client, self.m_asic, port, spool, ipspThre_p)
116 if (result != OpEN.OPEN_E_NONE) :
117 print "Error ! failed to set IPSP threshold"
119 OpEN.delete_OPEN_BST_INGRESS_PORT_SP_THRESHOLD_tp(ipspThre_p)
121 def show_ippg_stat(self):
122 """ Build all arguments to be passed """
123 ippg_p = OpEN.new_OPEN_BST_INGRESS_PORT_PG_DATA_tp()
124 time_p = OpEN.new_time_tp()
125 cnt_p = OpEN.new_uint32_tArray(2)
127 result = OpEN.openapiBstIppgDataGet(self.m_client, self.m_asic, ippg_p, time_p)
128 if (result != OpEN.OPEN_E_NONE) :
129 print "Error ! failed to get IPPG stat"
131 print "Showing IPPG Statistics"
132 print "==============================================="
133 for port
in range(0, self.m_ports):
135 for pg
in range(0, self.m_pg):
136 print "Port %d, Pririty Group %d - " % (port + 1, pg),
137 OpEN.GetIPPGData(ippg_p, port, pg, cnt_p)
138 print "[%d , %d]" % (OpEN.uint32_tArray_getitem(cnt_p, 0),
139 OpEN.uint32_tArray_getitem(cnt_p, 1))
141 OpEN.delete_time_tp(time_p)
142 OpEN.delete_uint32_tp(cnt_p)
143 OpEN.delete_OPEN_BST_INGRESS_PORT_PG_DATA_tp(ippg_p)
145 def config_bst_feature(self, enable, mode):
147 print "Setting and Getting Bst feature"
148 print "========================================="
149 bstCfg_p = OpEN.new_OPEN_BST_CONFIG_tp()
150 bstCfg = OpEN.OPEN_BST_CONFIG_tp_value(bstCfg_p)
151 bstCfg.enableStatsMonitoring = enable
152 bstCfg.enableDeviceStatsMonitoring = 1
153 bstCfg.enableIngressStatsMonitoring = 1
154 bstCfg.enableEgressStatsMonitoring = 0
157 print "Setting values and getting - enableStatsMonitoring - %d, mode - %d" % (bstCfg.enableStatsMonitoring, bstCfg.mode)
158 OpEN.OPEN_BST_CONFIG_tp_assign(bstCfg_p, bstCfg)
159 result=OpEN.openapiBstConfigSet(self.m_client, self.m_asic, bstCfg_p)
161 if result == OpEN.OPEN_E_NONE :
163 bstCfg.enableStatsMonitoring = 0
165 OpEN.OPEN_BST_CONFIG_tp_assign(bstCfg_p, bstCfg)
166 result=OpEN.openapiBstConfigGet(self.m_client, self.m_asic, bstCfg_p)
167 bstCfg = OpEN.OPEN_BST_CONFIG_tp_value(bstCfg_p)
169 print "Error ! failed to set bst feature"
172 print_sanity_results(result, ((bstCfg.enableStatsMonitoring == enable)
and (bstCfg.mode == mode)) ,
"bst feature config ",
"set and get")
174 OpEN.delete_OPEN_BST_CONFIG_tp(bstCfg_p)
176 def show_esp_stat(self):
177 """ Build all arguments to be passed """
178 esp_p = OpEN.new_OPEN_BST_EGRESS_SP_DATA_tp()
179 time_p = OpEN.new_time_tp()
180 cnt_p = OpEN.new_uint32_tArray(3)
182 result = OpEN.openapiBstEspDataGet(self.m_client, self.m_asic, esp_p, time_p)
183 if (result != OpEN.OPEN_E_NONE) :
184 print "Error ! failed to get ESP stat"
187 print "Showing ESP Statistics"
188 print "==============================================="
189 for sp
in range(0, self.m_spool):
190 print "Service Pool %d - " % (sp),
191 OpEN.GetESPData(esp_p, sp, cnt_p)
192 print "[%d , %d, %d]" % (OpEN.uint32_tArray_getitem(cnt_p, 0),
193 OpEN.uint32_tArray_getitem(cnt_p, 1), OpEN.uint32_tArray_getitem(cnt_p, 2))
195 OpEN.delete_time_tp(time_p)
196 OpEN.delete_uint32_tp(cnt_p)
197 OpEN.delete_OPEN_BST_EGRESS_SP_DATA_tp(esp_p)
199 def show_ipsp_threshold(self):
200 """ Build all arguments to be passed """
201 snap_p = OpEN.new_OPEN_BST_ASIC_SNAPSHOT_DATA_tp()
202 ucq_p = OpEN.new_OPEN_BST_EGRESS_UC_QUEUE_DATA_tp()
203 mcq_p = OpEN.new_OPEN_BST_EGRESS_MC_QUEUE_DATA_tp()
204 time_p = OpEN.new_time_tp()
205 thre_p = OpEN.new_uint32_tp()
207 """ Call OpEN API to get threshold values """
208 result = OpEN.openapiBstThresholdGet(self.m_client, self.m_asic, snap_p, ucq_p, mcq_p, time_p)
209 snap = OpEN.OPEN_BST_ASIC_SNAPSHOT_DATA_tp_value(snap_p)
210 ipsp_p = OpEN.copy_OPEN_BST_INGRESS_PORT_SP_DATA_tp(snap.iPortSp)
212 if result != OpEN.OPEN_E_NONE :
213 print "Error ! failed to get IPSP threshold"
216 print "Showing IPSP Threshold"
217 print "==============================================="
218 for port
in range(0, self.m_ports):
219 print "Port %d - [" % (port + 1),
220 for sp
in range(0, self.m_spool):
221 OpEN.GetIPSPData(ipsp_p, port, sp, thre_p)
222 thre = OpEN.uint32_tp_value(thre_p)
224 print ", %d" % (thre),
226 print "%d " % (thre),
229 OpEN.delete_time_tp(time_p)
230 OpEN.delete_uint32_tp(thre_p)
231 OpEN.delete_OPEN_BST_ASIC_SNAPSHOT_DATA_tp(snap_p)
232 OpEN.delete_OPEN_BST_EGRESS_UC_QUEUE_DATA_tp(ucq_p)
233 OpEN.delete_OPEN_BST_EGRESS_MC_QUEUE_DATA_tp(mcq_p)
234 OpEN.delete_OPEN_BST_INGRESS_PORT_SP_DATA_tp(ipsp_p)
237 """Demonstrate OpEN usage for BST APIs"""
239 ret = open_.connect(
"instru_example")
240 if ret == OpEN.OPEN_E_NONE :
241 open_.getNetworkOSVersion()
242 client = open_.get_client()
244 example = InstruExample(client, 0)
245 example.show_asic_capability()
246 example.config_bst_feature(1, OpEN.OPEN_BST_MODE_PEAK)
247 example.show_ippg_stat()
248 example.show_esp_stat()
249 example.show_ipsp_threshold()
250 example.config_ipsp_threshold(0, 5, 4160)
251 example.config_ipsp_threshold(0, 7, 2288)
252 example.config_ipsp_threshold(0, 8, 7696)
253 example.show_ipsp_threshold()
257 print "Unable to connect"
259 if __name__ ==
'__main__': main()