If only pid and eid are given, prints out information about all ports in theexperiment. Otherwise, output is limited to the nodes and/or ports given.NOTE: Statistics are reported from the switch's perspective. This means that'In' packetsarethosesentFROMthenode,and'Out'packetsarethosesentTOthenode.Intheoutput,packetsdescribedas'NUnicast'or'NUcast'arenon-unicast

## First, make sure the experiment exists#if(!ExpState($pid,$eid)){die"There is no experiment $eid in project $pid\n";}## Make sure they have access to it#if(!TBExptAccessCheck($UID,$pid,$eid,TB_EXPT_READINFO)){die"You do not have permission to view experiment $pid/$eid\n";}snmpit_lib::init(0);## Get a list of all ports in the experiment#my@experimentPorts=getExperimentPorts($pid,$eid);my@ports;if(@passedPorts){## Handle a set of passed-in ports#foreachmy$port(@passedPorts){$port=~/^([^:]+)(:(\d+))?$/;my($hostname,$portnumber)=($1,$3);my$nodeid;if(!VnameToNodeid($pid,$eid,$hostname,\$nodeid)){die"There is no node $hostname in $pid/$eid\n";}if(defined($portnumber)){# They gave us a specific interfacepush@ports,"$nodeid:$portnumber";}else{# We need to find all experimental ports for this nodepush@ports,grep(/^$nodeid:(\d+)$/,@experimentPorts);}}}else{## They didn't ask for specific ports, so we'll use 'em all#@ports=@experimentPorts;}## List of OIDs we want to look at for each port### Find out which devices these ports are on#my%portMap=mapPortsToDevices(@ports);my@stats;foreachmy$name(keys%portMap){my@ports=@{$portMap{$name}};## Connect to the switch and get the data we want off of it#

## Figure out which port on which switch this corresponds to#my$switchport=portnum($port);if(!($switchport&&($switchport=~/(.+):(\d+)\.(\d+)/))){warn"WARNING: No switch port found for $port\n";}else{my($switch_id,$switch_card,$switch_port)=($1,$2,$3);my$dbresult=DBQueryFatal("select * from port_counters where "."node_id='$switch_id' and card=$switch_card and "."port=$switch_port");my$oldresult=[@$result];## Unless they want absolute counters, go through and subtract# out the values stored in the database#if(!$opt{c}){if($dbresult&&$dbresult->num_rows()){my%oldvals=$dbresult->fetchhash();for(my$i=0;$i<@oids;$i++){if($oldvals{$oids[$i]}){$result->[$i]-=$oldvals{$oids[$i]};}}}}## If requested, update the counters in the database#if($opt{z}){## What we do to the DB depends on whether or not there is# already an entry for this port#my$query;if($dbresult->num_rows()){$query="update port_counters set ";}else{$query="insert into port_counters set ";}my@query_terms=();for(my$i=0;$i<@oids;$i++){push@query_terms,"$oids[$i]=$oldresult->[$i] ";}$query.=join(",",@query_terms);if($dbresult->num_rows()){$query.=" where node_id='$switch_id' and "."card=$switch_card and port=$switch_port";}else{$query.=", node_id='$switch_id', card=$switch_card, "."port=$switch_port";}DBQueryFatal($query);}}

## Try to translate the port name to the node's vname#$port=~/^(.+):(\d+)/;if($1){my$portnum=$2;my($junk,$vname);NodeidToExp($1,\$junk,\$junk,\$vname);$port="$vname:$portnum";}## Throw this onto a list, so that we can sort it#push@stats,[$port,@$result];}}