This chapter shows a number of examples of VSE script files (located in the installation directory: C:\Users\Public\Documents\LeCroy\Net Protocol Suite\Examples\VSE).
Example Script 1: Custom Progress
Python
# This example disables VSE's auto progress and reports the reverse progress manually
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
total_items = Trace.ItemCount
# This callback will be called for each event in the trace
def OnEvent(item) :
global total_items
Output.SetProgress(0, total_items, total_items - item.EventNumber)
# Continue traversing
return True
# Create a VSE configuration to traverse all Ethernet items
config = CVSEConfig()
# Turn off auto progress
config.AutoProgress = False
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# Set the result to success
Output.Result = VSEResult.Success
Example Script 2: Ethernet Types
Python
# This example counts all Ethernet types in the trace and shows the number of
# each type at the end.
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
ethernet_types = dict()
# This callback will be called for each event in the trace
def OnEvent(item) :
global ethernet_types
type_item = item["Ethernet Header.Ethernet Type"]
if type_item :
type = type_item.Data
if type in ethernet_types :
current_type = ethernet_types[type]
current_type[0] += 1
else :
ethernet_types[type] = [1, type_item.DecodedData]
# Continue traversing
return True
# Create a VSE configuration to travese all Ethernet items
config = CVSEConfig()
config.TraverseOrder = TraceTraverseOrder.Linear
config.TraverseType = TraceTraverseType.Event
# Send no items but Ethernet
config.SendItem(VSEItemType.NoneExcept)
config.SendItem(GEVSEItemType.Ethernet)
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# Print out the results
for k, v in ethernet_types.items():
Output.AppendLog("Number of " + v[1] + " is: " + str(v[0]) + "\r\n")
# Set the result to success
Output.Result = VSEResult.Success
Example Script 3: Failure on Error
Python
# This example traverse on all of the trace items and report failure as
# soon as it reaches the first protocol error
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
# This callback will be called for each event in the trace
def OnEvent(item) :
if item.HasError :
Output.AppendLog("Item number " + str(item.EventNumber) + " has error.")
Output.Result = VSEResult.Failure
# Stop traversing
return False
# Continue traversing
return True
# Process VSE with default configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(CVSEConfig(), OnEvent)
# If the result is not already set then it means no errors found so set it to success.
if Output.Result == VSEResult.NoResult :
Output.Result = VSEResult.Success
Example Script 4: FCP Frame Count
Python
# This example counts all FCP Frames in the trace and shows the number of
# each type at the end.
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
fc_info = dict()
# This callback will be called for each event in the trace
def OnEvent(item) :
global fc_info
rctl_item = item["Frame Header.R_CTL"]
type_item = item["Frame Header.TYPE"]
if rctl_item and type_item :
key = rctl_item.Data * 256 + type_item.Data
if key in fc_info :
current_info = fc_info[key]
current_info[0] += 1
else :
fc_info[key] = [1, rctl_item.DecodedData]
# Continue traversing
return True
# Create a VSE configuration to travese all FC items
config = CVSEConfig()
config.TraverseOrder = TraceTraverseOrder.Linear
config.TraverseType = TraceTraverseType.Event
# Send no items but FC
config.SendItem(VSEItemType.NoneExcept)
config.SendItem(GEVSEItemType.FC)
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# Shows how many of each FCP frame type found in the trace.
for k, v in fc_info.items():
Output.AppendLog("Number of " + v[1] + " is: " + str(v[0]))
# Set the result to success
Output.Result = VSEResult.Success
Example Script 5: GE Errors Count
Python
# This example count all protocol errors in the trace and print out the number of
# each error type. It also shows the total number of events with protocol error.
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
# Convenient dictionary to translate protocol errors to string
GEErrors = {
GETraceItemError.DELIMITER_ERROR: 'DELIMITER_ERROR',
GETraceItemError.FRAME_LENGTH_ERROR: 'FRAME_LENGTH_ERROR',
GETraceItemError.ETHERNET_CRC_ERROR: 'ETHERNET_CRC_ERROR',
GETraceItemError.FC_CRC_ERROR: 'FC_CRC_ERROR',
GETraceItemError.BLOCK_TYPE_ERROR: 'BLOCK_TYPE_ERROR',
GETraceItemError.ORDER_SET_ERROR: 'ORDER_SET_ERROR',
GETraceItemError.ALIGNMENT_ERROR: 'ALIGNMENT_ERROR',
GETraceItemError.SYNC_HEADER_ERROR: 'SYNC_HEADER_ERROR',
GETraceItemError.FEC_ERROR: 'FEC_ERROR',
GETraceItemError.AUTO_NEG_FRAME_MARKER_ERROR: 'AUTO_NEG_FRAME_MARKER_ERROR',
GETraceItemError.AUTO_NEG_MANCHESTER_ERROR: 'AUTO_NEG_MANCHESTER_ERROR',
GETraceItemError.MARKER_INTERVAL_ERROR: 'MARKER_INTERVAL_ERROR',
GETraceItemError.TRAINING_FRAME_MARKER_ERROR: 'TRAINING_FRAME_MARKER_ERROR',
GETraceItemError.TRAINING_MANCHESTER_ERROR: 'TRAINING_MANCHESTER_ERROR',
GETraceItemError.CHECKSUM_ERROR: 'CHECKSUM_ERROR',
GETraceItemError.ECN_ERROR: 'ECN_ERROR'
}
errors_info = dict()
errors_count = 0
# This callback will be called for each event in the trace
def OnEvent(item) :
global errors_info
global errors_count
if item.HasError :
errors_count += 1
for e in item.ErrorList :
if e in errors_info :
errors_info[e] += 1;
else :
errors_info[e] = 1
# Continue traversing
return True
# Create a VSE configuration to travese all Ethernet items
config = CVSEConfig()
config.TraverseOrder = TraceTraverseOrder.Linear
config.TraverseType = TraceTraverseType.Event
# Send no items but Ethernet
config.SendItem(VSEItemType.NoneExcept)
config.SendItem(GEVSEItemType.Ethernet)
config.SendItem(GEVSEItemType.Primitive)
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# Print out the results
Output.AppendLog("Total number of events with error: " + str(errors_count))
for k, v in errors_info.items():
Output.AppendLog("Number of " + GEErrors[k] + " is: " + str(v))
# Set the result to success
Output.Result = VSEResult.Success
Example Script 6: Success On Read10
Python
# This example reports success as soon as it finds the first item with
# SCSI opcode Read10 on all ports except port 1
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
# This callback will be called for each event in the trace
def OnEvent(item) :
fc_item = item["Data.FCP_CDB.Operation Code"]
if fc_item and fc_item.Data == 0x28 :
Output.Result = VSEResult.Success;
# Stop traversing
return False
ethernet_item = item["Payload.iSCSI.CDB.Operation Code"]
if ethernet_item and ethernet_item.Data == 0x28 :
Output.Result = VSEResult.Success;
# Stop traversing
return False
# Continue traversing
return True
# Create a VSE configuration to travese all Ethernet items
config = CVSEConfig()
# Send all ports but port 1
config.SendPort(VSEPort.AllExcept)
config.DontSendPort(1)
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# If the result is not already set then it means no Read10 found so set it to failure.
if Output.Result == VSEResult.NoResult :
Output.Result = VSEResult.Failure
Example Script 7: Success On Read10 (Using DontSendPort_2)
Python
# This example reports success as soon as it finds the first item with
# SCSI opcode Read10 on all ports except port 1
Output.AppendLog(Trace.Name + " has " + str(Trace.ItemCount) + " items.")
# This callback will be called for each event in the trace
def OnEvent(item) :
fc_item = item["Data.FCP_CDB.Operation Code"]
if fc_item and fc_item.Data == 0x28 :
Output.Result = VSEResult.Success;
# Stop traversing
return False
ethernet_item = item["Payload.iSCSI.CDB.Operation Code"]
if ethernet_item and ethernet_item.Data == 0x28 :
Output.Result = VSEResult.Success;
# Stop traversing
return False
# Continue traversing
return True
# Create a VSE configuration to travese all ethernet items
config = CVSEConfig()
# Send all ports but port 1
config.SendPort(VSEPort.AllExcept)
config.DontSendPort_2(1, 1)
# Process VSE with the specified configurations and call OnEvent callback
# for each item.
Trace.ProcessVSE(config, OnEvent)
# If the result is not already set then it means no Read10 found so set it to failure.
if Output.Result == VSEResult.NoResult :
Output.Result = VSEResult.Failure