This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Add function to code

Help for those learning Tcl or writing their own scripts.
Post Reply
c
chef06
Voice
Posts: 1
Joined: Mon Dec 09, 2013 4:25 am

Add function to code

Post by chef06 »

Hello, I want to set up Smartbits. I found some examples script. It is ok. Now I want to create this script - add information about Counters ($GIG_STRUC_COUNTER_INFO).
I try add this function to code, but I can not display it.
Please can I some who help me create code. I do not undestand struct_new and etc.
Thaks very much.

Code: Select all

###################################################################################
# GIGCount.tcl                                                                    #
#                                                                                 #
# - Sets a group of Gigabit cards (slot 1 and 3).                                 #
#                                                                                 #
# - We create an array of counter structures to hold the group counter data,      #
#   then draw a simple report and fill in the counter data.                       #
#                                                                                 #
# NOTE: This script works on the following cards:                                 #
#       - GX-1405(B)                                                              #
#       - GX-1420(B)                                                              #
#       - LAN-6200A                                                               #
#       - LAN-6201A                                                               #
#       - LAN-3300A/3310A                                                         #
#                                                                                 #
###################################################################################

# If smartlib.tcl is not loaded, attempt to locate it at the default location.
# The actual location is different on different platforms. 
if  {$tcl_platform(platform) == "windows"} {
      set libPath "smartlib.tcl"
} else {
         set libPath "../../../../include/smartlib.tcl"
}
# if "smartlib.tcl" is not loaded, try to source it from the default path
if { ! [info exists __SMARTLIB_TCL__] } {
     if {[file exists $libPath]} {
          source $libPath
} else {   
               
         #Enter the location of the "smartlib.tcl" file or enter "Q" or "q" to quit
         while {1} {
         
                     puts "Could not find the file $libPath."
                     puts "Enter the path of smartlib.tcl, or q to exit." 
          
                     gets stdin libPath
                     if {$libPath == "q" || $libPath == "Q"} {
                          exit
                     } 
                     if {[file exists $libPath]} {
	                  source $libPath
                          break
                     } 
       
         } 
   }
}

# If chassis is not currently linked prompt for IP and link  
if {[ETGetLinkStatus] < 0} {
     puts "SmartBits not linked - Enter chassis IP address"
     gets stdin ipaddr
     set retval [ETSocketLink $ipaddr 16385]  
     if {$retval < 0 } {
	  puts "Unable to connect to $ipaddr. Please try again."
	  exit
     }
}


set iHub 0
set iPort 0

set iSlot 0	
set iSlot2 2

#LIBCMD HTResetPort $RESET_FULL $iHub $iSlot $iPort
#LIBCMD HTResetPort $RESET_FULL $iHub $iSlot2 $iPort

# Create a group of two cards
LIBCMD HGSetGroup ""
LIBCMD HGAddtoGroup $iHub $iSlot $iPort
LIBCMD HGAddtoGroup $iHub $iSlot2 $iPort

#############################################
# Initialize transmit parameters            #
# single stream (no alternate) with no VFDs #
#############################################

LIBCMD HTSetStructure $GIG_STRUC_TX 1 1 1 - 0 $iHub $iSlot $iPort \
	-ulGap 9600
LIBCMD HTSetStructure $GIG_STRUC_TX 0 0 0 - 0 $iHub $iSlot2 $iPort \
	-ulGap 9600
# LIBCMD HTGetStructure $GIG_STRUC_COUNTER_INFO 0 0 0 \ myGIGCounterInfo \ 0 \ $iHub $iSlot $iPort

# Reset Counters
LIBCMD HGClearPort

# Transmit for four seconds          
puts "Sending Packets..."
LIBCMD HGStart 

after 4000			
LIBCMD HGStop				
puts "Done!"

# Pause a second to stabilize counters
after 1000			
###############################################################################
# Counters                                                                    #
# - We create an array of two structures of type HTCountStructure             #
#   then call HGGetCounters to retireve data from cards.                      #
#   This is the same procedure used for all L2 cards.                         #
#                                                                             #
# - We add 1 to $iSlot and $iSlot2 to match the slot number on the chassis    #
#                                                                             #
# - Use format to align count data (10d allows 10 spaces decimal output).     #
###############################################################################

struct_new cs HTCountStructure*2

LIBCMD HGGetCounters cs

puts "------------------------------------------------------------"
puts "			Vysledky testu"
puts "------------------------------------------------------------"
puts "    	            Card [expr $iSlot + 1]		Card [expr $iSlot2 +1]"
puts "------------------------------------------------------------"
puts "Tx Packets 	[format %10d "$cs(0.TmtPkt)"]	|  [format %10d "$cs(1.TmtPkt)"]"
puts "Rx Packets 	[format %10d "$cs(0.RcvPkt)"]	|  [format %10d "$cs(1.RcvPkt)"]"
puts "Collisions	[format %10d "$cs(0.Collision)"]	|  [format %10d "$cs(1.Collision)"]"
puts "Recvd Trigger	[format %10d "$cs(0.RcvTrig)"]	|  [format %10d "$cs(1.RcvTrig)"]"
puts "CRC Errors	[format %10d "$cs(0.CRC)"]	|  [format %10d "$cs(1.CRC)"]"
# puts "Nmb of    	[format %10d "$cs(0.RcvPktRate)"]	|  [format %10d "$cs(1.RcvPktRate)"]"
puts "------------------------------------------------------------"

#Unset the structure
unset cs

puts "UnLinking from the chassis.."
ETUnLink
puts "DONE!"
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'd like to advice you that this is a heavily eggdrop-oriented forum, and I don't see how this is in any way related to eggdrops (or standard tcl, for that matter).

This seems to be heavily-reliant on a 3rd-party library related to some network analyzer? of which I can't find much usable information on the net.

All in all, I wouldn't get my hopes up too high here.
NML_375
Post Reply