[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Paced transmission code



Peter -

A couple of things:

1. add a .forward to your bmrc account to your uclink account if that is
your home email location.

2. i have attached the code below. The code isn't very clean - we ran
into a problem implementing variable passing by reference for advance,
but it shows the principle.

At the meeting last friday I showed how you can calculate the number of
packets to send per second depending on the bitrate of the mpeg stream. 
I suggest you do a 4 mbs stream which is 500 KBytes/sec. Now, assume the
amount of data that you can send in each packet is 1500 bytes, that says
you need to send 334 packets per second which is roughly one packet ever
3 milliseconds.

I would do this calculation more precisely - find out exactly how many
data bytes are in each packet you send, compute the actual number of
packets that must be sent per second and then do that.  Since 3
milliseconds is a small number to be doing rescheduling, you might want
to send 2-3 packets at a time and do it every 9 msecs.

We need to figure out how many packets a second the mash code can send
on a modern computer - any volunteers to do this experiment?
	Larry
-- 
Professor Lawrence A. Rowe          Internet:  Rowe@BMRC.Berkeley.EDU
Computer Science Division - EECS       Phone: 510-642-5117
University of California, Berkeley       Fax: 510-642-5615
Berkeley, CA 94720-1776            URL: http://bmrc.berkeley.edu/~larry

---

# Leaky bucket simulation
# Code to demonstrate paced sending of packets

# We keep a queue, tcl array "q", with two pointers: 
#	"enq" - index to next open slot to enter item
#	"deq" - index of next slot to dequeue item from
# if $enq==$deq, the queue is empty.  A full queue has
# ($enq+1)==$deq.  The queue size is specified by QSIZE
#
# The queue abstraction is implemented by the functions:
#	isfull - is the queue full?
#	advance - move the queue index mod the size of the queue
#	enq(msg) - add $msg to the queue
#	deq - removes the first item in the queue and returns it

# The paced transmission is implemented by the two functions
#	loadq - add N items to the queue
#	dosend - callback function that sends one message from the queue
# Notice that the queue is loaded every 10 seconds with 8 items
# that are then sent at 1 second intervals. 

set QSIZE 10
set enq 0
set deq 0
set lenq 0

proc isfull {} {
  global enq deq lenq
  set lenq [advance $enq]
  if {$lenq==$deq} {
    return 1
  }
  return 0
}

proc advance {x} {
  global QSIZE
  incr x
  if {$x==$QSIZE} {
    set x 0
  }
  return $x
}

proc enque {msg} {
  global enq q
  if {[isfull]} {
    puts stdout "DROP: $msg"
    return
  }
  set q($enq) $msg
  set enq [advance $enq]
}

proc deque {} {
  global q enq deq
  if {$enq==$deq} {
    puts stdout "UNDERFLOW"
    return
  }
  puts -nonewline stdout "SEND: "
  puts -nonewline stdout [clock format [clock seconds] -format "%T"]
  puts stdout "$q($deq)"
  set deq [advance $deq]
}

proc loadq {} {
  foreach i {1 2 3 4 5 6 7 8} {
    enque $i
  }
  after 10000 loadq
}

proc dosend {} {
  deque
  after 1000 dosend
}