<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-CA">
	<id>https://nmsl.cs.sfu.ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ysa57</id>
	<title>NMSL - User contributions [en-ca]</title>
	<link rel="self" type="application/atom+xml" href="https://nmsl.cs.sfu.ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ysa57"/>
	<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php/Special:Contributions/Ysa57"/>
	<updated>2026-05-02T19:05:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2641</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2641"/>
		<updated>2009-03-13T17:47:41Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
== Implementations ==&lt;br /&gt;
&lt;br /&gt;
=== Done Classes ===&lt;br /&gt;
&lt;br /&gt;
=== Work-on-progress Classes ===&lt;br /&gt;
Event (ysa57)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// the following classes implement the Galois field [in case of network coding]&lt;br /&gt;
// coefficients should be selected randomly from Galois field&lt;br /&gt;
class ExtendedGaloisField extends GaloisField { // extension of Galois field where you can create  &lt;br /&gt;
                                                                     //the field with a predefined base and power&lt;br /&gt;
     GaloisPolynomial[] alfaPowers;&lt;br /&gt;
     GaloisPolynomial moduloPoly;&lt;br /&gt;
     char alfa;&lt;br /&gt;
     GaloisField base;&lt;br /&gt;
     int pwr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class GaloisField { // implementing the Galois field&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class GaloisPolynomial { //working with Polynomials&lt;br /&gt;
     private int[] coefs; // coefs are selected from Galois field&lt;br /&gt;
     private char alfa;&lt;br /&gt;
     private GaloisField field;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class GaloisException{ &lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for network coding =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Playback quality (PSNR)&lt;br /&gt;
2. Resilience to peer dynamics (ability of maintaning good streaming quality) &lt;br /&gt;
3. Required server capacity&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to &amp;quot;http://www.soyatec.com/euml2/installation/&amp;quot;, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
4. How to use: after you creating a new java project, go to File -&amp;gt; New -&amp;gt; Other, select the &amp;quot;UML2 Class Diagram&amp;quot; under the eUML directory,&lt;br /&gt;
    then you can create a class diagram for your project .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add &amp;quot;http://subclipse.tigris.org/update_1.4.x&amp;quot; to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
5. Go to Window -&amp;gt; Preferences -&amp;gt; Team. If you can see SVN under the Team tab, congratulations, your installation is done. &lt;br /&gt;
6. How to use: right click the project you want to commit, select Tean -&amp;gt; Share project -&amp;gt; SVN, input the URL of &lt;br /&gt;
    your svn server, then you can import your project to it. &lt;br /&gt;
7. For more details on how to use subclipse, please refer to &lt;br /&gt;
     http://www.ibm.com/developerworks/opensource/library/os-ecl-subversion/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= The project directory =&lt;br /&gt;
I've put the psim project to &amp;quot;https://cs-svn.cs.surrey.sfu.ca/svn/nsl/schedule/psim&amp;quot;. You can check it out in eclipse with subclipse.&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2640</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2640"/>
		<updated>2009-03-11T22:25:29Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// the following classes implement the Galois field [in case of network coding]&lt;br /&gt;
// coefficients should be selected randomly from Galois field&lt;br /&gt;
class ExtendedGaloisField extends GaloisField { // extension of Galois field where you can create  &lt;br /&gt;
                                                                     //the field with a predefined base and power&lt;br /&gt;
     GaloisPolynomial[] alfaPowers;&lt;br /&gt;
     GaloisPolynomial moduloPoly;&lt;br /&gt;
     char alfa;&lt;br /&gt;
     GaloisField base;&lt;br /&gt;
     int pwr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class GaloisField { // implementing the Galois field&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class GaloisPolynomial { //working with Polynomials&lt;br /&gt;
     private int[] coefs; // coefs are selected from Galois field&lt;br /&gt;
     private char alfa;&lt;br /&gt;
     private GaloisField field;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class GaloisException{ &lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for network coding =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Playback quality (PSNR)&lt;br /&gt;
2. Resilience to peer dynamics (ability of maintaning good streaming quality) &lt;br /&gt;
3. Required server capacity&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to &amp;quot;http://www.soyatec.com/euml2/installation/&amp;quot;, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
4. How to use: after you creating a new java project, go to File -&amp;gt; New -&amp;gt; Other, select the &amp;quot;UML2 Class Diagram&amp;quot; under the eUML directory,&lt;br /&gt;
    then you can create a class diagram for your project .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add &amp;quot;http://subclipse.tigris.org/update_1.4.x&amp;quot; to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
5. Go to Window -&amp;gt; Preferences -&amp;gt; Team. If you can see SVN under the Team tab, congratulations, your installation is done. &lt;br /&gt;
6. How to use: right click the project you want to commit, select Tean -&amp;gt; Share project -&amp;gt; SVN, input the URL of &lt;br /&gt;
    your svn server, then you can import your project to it. &lt;br /&gt;
7. For more details on how to use subclipse, please refer to &lt;br /&gt;
     http://www.ibm.com/developerworks/opensource/library/os-ecl-subversion/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= The project directory =&lt;br /&gt;
I've put the psim project to &amp;quot;https://cs-svn.cs.surrey.sfu.ca/svn/nsl/schedule/psim&amp;quot;. You can check it out in eclipse with subclipse.&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2627</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2627"/>
		<updated>2009-03-11T05:42:43Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to http://www.soyatec.com/euml2/installation/, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
4. How to use: after you creating a new java project, go to File -&amp;gt; New -&amp;gt; Other, select the &amp;quot;UML2 Class Diagram&amp;quot; under the eUML directory,&lt;br /&gt;
    then you can create a class diagram for your project .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add http://subclipse.tigris.org/update_1.4.x to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
5. Go to Window -&amp;gt; Preferences -&amp;gt; Team. If you can see SVN under the Team tab, congratulations, your installation is done. &lt;br /&gt;
6. How to use: right click the project you want to commit, select Tean -&amp;gt; Share project -&amp;gt; SVN, input the URL of &lt;br /&gt;
    your svn server, then you can import your project to it. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2626</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2626"/>
		<updated>2009-03-11T05:42:09Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to http://www.soyatec.com/euml2/installation/, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
4. How to use: after you create a new java project, go to File -&amp;gt; New -&amp;gt; Other, select the &amp;quot;UML2 Class Diagram&amp;quot; under the eUML directory,&lt;br /&gt;
    then you can create a class diagram for your project .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add http://subclipse.tigris.org/update_1.4.x to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
5. Go to Window -&amp;gt; Preferences -&amp;gt; Team. If you can see SVN under the Team tab, congratulations, your installation is done. &lt;br /&gt;
6. How to use: right click the project you want to commit, select Tean -&amp;gt; Share project -&amp;gt; SVN, input the URL of &lt;br /&gt;
    your svn server, then you can import your project to it. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2625</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2625"/>
		<updated>2009-03-11T05:33:42Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to http://www.soyatec.com/euml2/installation/, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add http://subclipse.tigris.org/update_1.4.x to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
5. Go to Window -&amp;gt; Preferences -&amp;gt; Team. If you can see SVN under the Team tab, congratulations, your are done. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2624</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2624"/>
		<updated>2009-03-11T05:26:25Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                                  of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                            network coding]&lt;br /&gt;
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded&lt;br /&gt;
                                        blocks that has been received so far&lt;br /&gt;
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of  &lt;br /&gt;
                                        network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to install uml and svn tools in eclipse3.2.x = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*. Install emul2&lt;br /&gt;
1. Go to http://www.soyatec.com/euml2/installation/, download its free edition. (Select the right version according to your eclipse)&lt;br /&gt;
2. Unpack the zip file&lt;br /&gt;
3. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New local site&lt;br /&gt;
     then find the unpakced file to install it.&lt;br /&gt;
&lt;br /&gt;
*. Install subclipse&lt;br /&gt;
1. Open your eclipse, and go to Help -&amp;gt; Software Updates -&amp;gt; Find and install ... -&amp;gt; Search for new features to install -&amp;gt; New  Remote Site&lt;br /&gt;
2. Add http://subclipse.tigris.org/update_1.4.x to the URL field and add an arbitrary name to the Name field&lt;br /&gt;
3. Follow the instruction to install it.&lt;br /&gt;
4. If you encounter an error like &amp;quot;Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in &amp;quot;org.eclipse.mylyn.tasks.core (3.0.0)&amp;quot;&lt;br /&gt;
    don't worry, just deselect the &amp;quot;Integrations&amp;quot; item and continue to install.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2621</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2621"/>
		<updated>2009-03-10T22:12:03Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implements Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void join(Video vide); // the peer joins a group&lt;br /&gt;
    void leave(Video video); //the peer leaves the group&lt;br /&gt;
    //here we should call a scheduling algorithm to do the scheduling&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult();  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2620</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2620"/>
		<updated>2009-03-10T21:47:44Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; // encoded blocks&lt;br /&gt;
    Vector&amp;lt;Integer&amp;gt; decode(); // perform decoding process and return the original blocks of a segment&lt;br /&gt;
    void encode(); // perform encoding process on blocks of a segment&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class resultItem{ //this class records a scheduling item&lt;br /&gt;
   int peerID;&lt;br /&gt;
   int segID;&lt;br /&gt;
   long startTime; //start time of the peer to transmit this segment&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Vector&amp;lt;resultItem&amp;gt; item;    // result item: &amp;lt;peerID, segID, startTime&amp;gt; (we may write this vector to a log file later)&lt;br /&gt;
  long runningTime;                  //running time of the algorithm&lt;br /&gt;
  long deliveryRatio;                 //Average delivery ratio&lt;br /&gt;
&lt;br /&gt;
  double getDeliveryRatio();  //get the actual  average delivery ratio&lt;br /&gt;
  double getRunningTime(); //get the running time &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult(SchedulingResult);  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  SchedulingResult result;                 // create a schedulingResult object to store the result&lt;br /&gt;
  &lt;br /&gt;
  void schedule();                                   //implement the Scheduler interface&lt;br /&gt;
  void writeResult(SchedulingResult);  //write scheduling result to the result object of one scheduling period&lt;br /&gt;
                                                              //including calculating the average delivery ratio and running time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2617</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2617"/>
		<updated>2009-03-10T20:40:05Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial buffering time&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2616</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2616"/>
		<updated>2009-03-10T20:38:37Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial playback delay&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2615</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2615"/>
		<updated>2009-03-10T20:37:04Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial playback delay&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2614</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2614"/>
		<updated>2009-03-10T20:36:20Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Performance metrics for scheduling ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial playback delay&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2613</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2613"/>
		<updated>2009-03-10T20:35:28Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Performance metrics for scheduling =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here are some performance metrics:&lt;br /&gt;
1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled&lt;br /&gt;
2. Load balance among senders&lt;br /&gt;
3. Initial playback delay&lt;br /&gt;
4. Time and space complexity of the scheduling algorithm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2612</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2612"/>
		<updated>2009-03-10T20:23:14Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SysParam{ // system parameters that can be changed in each iteration of the simulation&lt;br /&gt;
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable  &lt;br /&gt;
                              // of serving to others [in case of network coding]&lt;br /&gt;
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of &lt;br /&gt;
                        // network coding]&lt;br /&gt;
}&lt;br /&gt;
    &lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
*&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2609</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2609"/>
		<updated>2009-03-10T19:53:17Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int endOffset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
* In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2608</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2608"/>
		<updated>2009-03-10T19:49:59Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int end Offset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
     //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently&lt;br /&gt;
                                           in order to get a small bitmap from them to do scheduleing, this message is sent&lt;br /&gt;
                                            when the receiver: jumps to view another part of the video or a new neighbor joins. &lt;br /&gt;
     //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information&lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
* In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2607</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2607"/>
		<updated>2009-03-10T19:37:12Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface Node { // a network node, currently can be either a tracker or a peer&lt;br /&gt;
}&lt;br /&gt;
                        &lt;br /&gt;
class Tracker implement Node { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
    void addPeer(Group group, Peer peer); // insert a peer into a video group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer implement Node { // represent a running peer&lt;br /&gt;
    int id; // sequential peer id&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; senders; // peers that we may send requests to &lt;br /&gt;
    Hashtable&amp;lt;Video, Vector&amp;lt;Connection&amp;gt;&amp;gt; receivers; // peers that we may send data to &lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
    void start(Video video); // start downloading a video &lt;br /&gt;
    void stop(Video video); // stop downloading&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently&lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,&lt;br /&gt;
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling&lt;br /&gt;
  int startOffset;         //the offset of the starting segment compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending segment compared with the start of the video&lt;br /&gt;
  double slidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int end Offset;&lt;br /&gt;
  void move();           // move the exchange window forward afte a scheduling period and do a next scheduling &lt;br /&gt;
  double getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Node src; // which peer generates this event&lt;br /&gt;
    Node dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. connectArrived: the connect message is received by the peer 2&lt;br /&gt;
    // 3. acceptSent: the potential sender reply with an accept message&lt;br /&gt;
    // 4. acceptArrived: the accept message arrives at the connection originator&lt;br /&gt;
    // 5. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 6. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 7. dataSent: a sender sends a data segment&lt;br /&gt;
    // 8. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 9. joinSent: a join message to the tracker&lt;br /&gt;
    // 10. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 11. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 12. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    // 13. scheduleStarted: a scheduling period started.&lt;br /&gt;
    // 14. scheduleEnded: a scheduling period ended. &lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
* In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2603</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2603"/>
		<updated>2009-03-10T04:48:31Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Neighbor { // keep track of what my neighbor has done&lt;br /&gt;
    Peer peer; // peer instance, for accessing availability info&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
    Connection conn; // e2e connection between us and another neighboring peer&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Tracker { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer { // represent a running peer&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Vector&amp;lt;Neighbor&amp;gt; neighbors; // peers that we may send requests to &lt;br /&gt;
    BufferedMatrix matrix; // matrix of coefficients and encoded values up to now&lt;br /&gt;
    NoEncodedBlocks noCodedBl; // keep track of No. of encoded blocks in each segment&lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; // growable 2 dimensional array corresponding to segments and layers&lt;br /&gt;
                          // each element in this vector keep the No. of encoded blocks in the   &lt;br /&gt;
                          // corresponding segment&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the up-to-date segments at the peer &lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
  int startOffset;         //the offset of the starting frame compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending frame compared with the start of the video&lt;br /&gt;
  double slideSpeed;  // the speed of sliding. The window goes forward continuously (or periodically?) at &lt;br /&gt;
                                  // the speed of the streaming rate.&lt;br /&gt;
  void getSlidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int end Offset;&lt;br /&gt;
  double slideSpeed;&lt;br /&gt;
  void getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Peer src; // which peer generates this event&lt;br /&gt;
    Peer dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connect: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 3. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 4. dataSent: a sender sends a data segment&lt;br /&gt;
    // 5. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 6. joinSent: a join message to the tracker&lt;br /&gt;
    // 7. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 8. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 9. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    //10. scheduleStarted: a scheduling period started.&lt;br /&gt;
    // 11. scheduleEnded: a scheduling period ended. &lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
  1. At the beginning, we should have a peer publish a video (or a trace file).&lt;br /&gt;
  2. The join() and leave() methods in the Group class may be moved to the Peer class and each peer&lt;br /&gt;
    should has a bitmap field.&lt;br /&gt;
  3. We may add a Tracker class:&lt;br /&gt;
    Class Tracker&lt;br /&gt;
    { &lt;br /&gt;
      URL url; //peers use this url to find the tracker&lt;br /&gt;
      Vector&amp;lt;Peer&amp;gt; peers;         //maintain a peer list to be quired by peers&lt;br /&gt;
      Vector&amp;lt;InetAddress&amp;gt; SelectPeers();  //when a peer joins a group at the first time, it quires other peers from the&lt;br /&gt;
                                                                  //tracker,  then the tracker invokes SelectPeers() and returns&lt;br /&gt;
                                                                 //a list of neighbors to that peer&lt;br /&gt;
      void recordPeer(); //record information of a peer when it first connects the tracker or update it when some old&lt;br /&gt;
                                    //information is already stored&lt;br /&gt;
                                   //the information exchanged between a tracker and a peer may be &amp;lt;peerID, videoName&amp;gt;&lt;br /&gt;
                                   // or &amp;lt;peerID, videoName, ip_Address, port&amp;gt; if we want to do simulation on different machines&lt;br /&gt;
    } &lt;br /&gt;
  4. If we really want to send video files between peers, we may need a Storage class to operate with files&lt;br /&gt;
  5. We may design a superclass of all peers, trackers, and neighbors, as a typical networking server to deal with&lt;br /&gt;
    network connections&lt;br /&gt;
  6. In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current   &lt;br /&gt;
    playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2602</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2602"/>
		<updated>2009-03-10T04:46:02Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Neighbor { // keep track of what my neighbor has done&lt;br /&gt;
    Peer peer; // peer instance, for accessing availability info&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
    Connection conn; // e2e connection between us and another neighboring peer&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Tracker { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer { // represent a running peer&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Vector&amp;lt;Neighbor&amp;gt; neighbors; // peers that we may send requests to &lt;br /&gt;
    BufferedMatrix matrix; // matrix of coefficients and encoded values up to now&lt;br /&gt;
    NoEncodedBlocks noCodedBl; // keep track of No. of encoded blocks in each segment&lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; // growable 2 dimensional array corresponding to segments and layers&lt;br /&gt;
                          // each element in this vector keep the No. of encoded blocks in the   &lt;br /&gt;
                          // corresponding segment&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the up-to-date segments at the peer &lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
  int startOffset;         //the offset of the starting frame compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending frame compared with the start of the video&lt;br /&gt;
  double slideSpeed;  // the speed of sliding. The window goes forward continuously (or periodically?) at &lt;br /&gt;
                                  // the speed of the streaming rate.&lt;br /&gt;
  void getSlidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int end Offset;&lt;br /&gt;
  double slideSpeed;&lt;br /&gt;
  void getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
   // should add more detail here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Peer src; // which peer generates this event&lt;br /&gt;
    Peer dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connect: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 3. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 4. dataSent: a sender sends a data segment&lt;br /&gt;
    // 5. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 6. joinSent: a join message to the tracker&lt;br /&gt;
    // 7. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 8. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 9. responseArrived: a response message reaches the receiver&lt;br /&gt;
   &lt;br /&gt;
    //10. scheduleStarted: a scheduling period started.&lt;br /&gt;
    // 11. scheduleEnded: a scheduling period ended. &lt;br /&gt;
&lt;br /&gt;
    //commet: how should we do when a scheduling period expires? &lt;br /&gt;
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
  1. At the beginning, we should have a peer publish a video (or a trace file).&lt;br /&gt;
  2. The join() and leave() methods in the Group class may be moved to the Peer class and each peer&lt;br /&gt;
    should has a bitmap field.&lt;br /&gt;
  3. We may add a Tracker class:&lt;br /&gt;
    Class Tracker&lt;br /&gt;
    { &lt;br /&gt;
      URL url; //peers use this url to find the tracker&lt;br /&gt;
      Vector&amp;lt;Peer&amp;gt; peers;         //maintain a peer list to be quired by peers&lt;br /&gt;
      Vector&amp;lt;InetAddress&amp;gt; SelectPeers();  //when a peer joins a group at the first time, it quires other peers from the&lt;br /&gt;
                                                                  //tracker,  then the tracker invokes SelectPeers() and returns&lt;br /&gt;
                                                                 //a list of neighbors to that peer&lt;br /&gt;
      void recordPeer(); //record information of a peer when it first connects the tracker or update it when some old&lt;br /&gt;
                                    //information is already stored&lt;br /&gt;
                                   //the information exchanged between a tracker and a peer may be &amp;lt;peerID, videoName&amp;gt;&lt;br /&gt;
                                   // or &amp;lt;peerID, videoName, ip_Address, port&amp;gt; if we want to do simulation on different machines&lt;br /&gt;
    } &lt;br /&gt;
  4. If we really want to send video files between peers, we may need a Storage class to operate with files&lt;br /&gt;
  5. We may design a superclass of all peers, trackers, and neighbors, as a typical networking server to deal with&lt;br /&gt;
    network connections&lt;br /&gt;
  6. In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current   &lt;br /&gt;
    playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2601</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2601"/>
		<updated>2009-03-10T01:09:19Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of&lt;br /&gt;
                    // block size and no blocks here&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    int blockSize; // blocks are fixed size, in bytes&lt;br /&gt;
    int noBlocks; // how many block here&lt;br /&gt;
    int dataSize; // aggregate size of all blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int totalSize; // total frame size in bytes, including all layers&lt;br /&gt;
    Hashtable&amp;lt;Integer, Layer&amp;gt; layers; // reference to layers of this frame, key is the layer id&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Neighbor { // keep track of what my neighbor has done&lt;br /&gt;
    Peer peer; // peer instance, for accessing availability info&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
    Connection conn; // e2e connection between us and another neighboring peer&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Tracker { // holds a set of groups/videos&lt;br /&gt;
    Vector&amp;lt;Group&amp;gt; groups; // all the video groups&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer { // represent a running peer&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    Vector&amp;lt;Neighbor&amp;gt; neighbors; // peers that we may send requests to &lt;br /&gt;
    BufferedMatrix matrix; // matrix of coefficients and encoded values up to now&lt;br /&gt;
    NoEncodedBlocks noCodedBl; // keep track of No. of encoded blocks in each segment&lt;br /&gt;
    Connection tracker; // control connection to the tracker&lt;br /&gt;
    Hashtable&amp;lt;Video, VideoBufMap&amp;gt; vBufMaps; // points to the video-level buffer map&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; join(Peer peer); // adding a new peer into this group, and return a list of senders&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class VideoBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, SegBufMap&amp;gt; sBufMaps; // points to segment bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SegBufMap {&lt;br /&gt;
    Hashtable&amp;lt;Integer, LayerBufMap&amp;gt; lBufMaps; // points to layer bufmap&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LayerBufMap {&lt;br /&gt;
    boolean avail; // availability bit for this (video, segment, layer) tuple&lt;br /&gt;
    NCBuf ncBuf; // network coding structure&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class NCBuf {&lt;br /&gt;
    boolean servCapibility; // Serving capability of each segment&lt;br /&gt;
                                      // show whether this segment is capable of serving other peers(applicable in NC)&lt;br /&gt;
    int noCodedBl; // growable 2 dimensional array corresponding to segments and layers&lt;br /&gt;
                          // each element in this vector keep the No. of encoded blocks in the   &lt;br /&gt;
                          // corresponding segment&lt;br /&gt;
    BufferedMatrix marix; // coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now&lt;br /&gt;
    Vector&amp;lt;Vector&amp;lt;Integer&amp;gt;&amp;gt; coef; // coefficients of the corresponding encoded blocks&lt;br /&gt;
    Vector &amp;lt;Integer&amp;gt;encodedValue; //encoded blocks&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SlidingWindow{ // the sliding window which contains all the up-to-date segments at the peer &lt;br /&gt;
                                  // set it to a fixed size, for example 1 minute of videos&lt;br /&gt;
  int startOffset;         //the offset of the starting frame compared with the start of the video&lt;br /&gt;
  int endOffset;           // the offset of the ending frame compared with the start of the video&lt;br /&gt;
  double slideSpeed;  // the speed of sliding. The window goes forward continuously (or periodically?) at &lt;br /&gt;
                                  // the speed of the streaming rate.&lt;br /&gt;
  void getSlidingWindowSize(); //get the size of the sliding window&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class exchangeWindow{ // the exchange window is the front part of the sliding window. &lt;br /&gt;
                                       //The unavailable segments in exchange window will be requested by the peer&lt;br /&gt;
                                       //usually we set it to a fixed size, for example, 10 seconds of video&lt;br /&gt;
                                       // the field of this class is similar to that of the SlidingWindow class&lt;br /&gt;
  int startOffset;&lt;br /&gt;
  int end Offset;&lt;br /&gt;
  double slideSpeed;&lt;br /&gt;
  void getSlidingWindowSize()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface Scheduler{ // any class wants to do scheduling should implement this interface&lt;br /&gt;
  void schedule() throws scheduleException; // the scheduling period is specified in the specific scheduling algorithm class&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class scheduleException{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SchedulingResult{                // this class is used to record scheduling results and do some statistics, &lt;br /&gt;
                                                      // for example, calculate the average delivery rate&lt;br /&gt;
  Tuple&amp;lt;int, int, double&amp;gt; log; //log file of the results. Each item of the tuple specifies the peerID, segmentID and&lt;br /&gt;
                                             // the starting time for the peer to transmit the segment &lt;br /&gt;
  double getDeliveryRatio();  //calculate the average delivery ratio&lt;br /&gt;
   // should add more detail here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm&lt;br /&gt;
  int schedulingPeriod;                     // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                             //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;                 // the scheduling results stored here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class LRF implements Scheduler{ // the Local Rarest First algorithm&lt;br /&gt;
  int schedulingPeriod;                  // scheduling period, for example, 2 seconds&lt;br /&gt;
  void schedule();                          //implement the Scheduler interface&lt;br /&gt;
  SchedulingResult result;              // the scheduling results stored here&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class RndGen { // common random number/event generators, to deal with&lt;br /&gt;
                       // 1. event: add new receiver for a group/video&lt;br /&gt;
                       // 2. event: remove a receiver from a group/video&lt;br /&gt;
                       // 3. number: peer's bandwidth&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Peer src; // which peer generates this event&lt;br /&gt;
    Peer dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connect: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 3. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 4. dataSent: a sender sends a data segment&lt;br /&gt;
    // 5. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
    // 6. joinSent: a join message to the tracker&lt;br /&gt;
    // 7. joinArrived: a join message reaches the tracker&lt;br /&gt;
    // 8. responseSent: a response message sent by the tracker&lt;br /&gt;
    // 9. responseArrived: a response message reaches the receiver&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
  1. At the beginning, we should have a peer publish a video (or a trace file).&lt;br /&gt;
  2. The join() and leave() methods in the Group class may be moved to the Peer class and each peer&lt;br /&gt;
    should has a bitmap field.&lt;br /&gt;
  3. We may add a Tracker class:&lt;br /&gt;
    Class Tracker&lt;br /&gt;
    { &lt;br /&gt;
      URL url; //peers use this url to find the tracker&lt;br /&gt;
      Vector&amp;lt;Peer&amp;gt; peers;         //maintain a peer list to be quired by peers&lt;br /&gt;
      Vector&amp;lt;InetAddress&amp;gt; SelectPeers();  //when a peer joins a group at the first time, it quires other peers from the&lt;br /&gt;
                                                                  //tracker,  then the tracker invokes SelectPeers() and returns&lt;br /&gt;
                                                                 //a list of neighbors to that peer&lt;br /&gt;
      void recordPeer(); //record information of a peer when it first connects the tracker or update it when some old&lt;br /&gt;
                                    //information is already stored&lt;br /&gt;
                                   //the information exchanged between a tracker and a peer may be &amp;lt;peerID, videoName&amp;gt;&lt;br /&gt;
                                   // or &amp;lt;peerID, videoName, ip_Address, port&amp;gt; if we want to do simulation on different machines&lt;br /&gt;
    } &lt;br /&gt;
  4. If we really want to send video files between peers, we may need a Storage class to operate with files&lt;br /&gt;
  5. We may design a superclass of all peers, trackers, and neighbors, as a typical networking server to deal with&lt;br /&gt;
    network connections&lt;br /&gt;
  6. In case of Network Coding when a peer joins a group it will receive segments that are 'n' seconds after the current   &lt;br /&gt;
    playback point. ('n' is a tunable parameter)&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2587</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2587"/>
		<updated>2009-03-05T22:22:55Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, a layer of it, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int size; // frame size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Neighbor { // keep track of what my neighbor has done&lt;br /&gt;
    Peer peer; // peer instance, for accessing availability info&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer { // represent a running peer&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    BitSet avail; // availability bufmap&lt;br /&gt;
    Vector&amp;lt;Neighbor&amp;gt; neighbors; // peers that we may send requests to &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    void join(Peer peer); // adding a new peer into this group&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Peer src; // which peer generates this event&lt;br /&gt;
    Peer dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connect: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 3. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 4. dataSent: a sender sends a data segment&lt;br /&gt;
    // 5. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
  1. At the beginning, we should have a peer publish a video (or a trace file).&lt;br /&gt;
  2. The join() and leave() methods in the Group class may be moved to the Peer class and each peer&lt;br /&gt;
    should has a bitmap field.&lt;br /&gt;
  3. We may add a Tracker class:&lt;br /&gt;
    Class Tracker&lt;br /&gt;
    { &lt;br /&gt;
      URL url; //peers use this url to find the tracker&lt;br /&gt;
      Vector&amp;lt;Peer&amp;gt; peers;         //maintain a peer list to be quired by peers&lt;br /&gt;
      Vector&amp;lt;InetAddress&amp;gt; SelectPeers();  //when a peer joins a group at the first time, it quires other peers from the&lt;br /&gt;
                                                                  //tracker,  then the tracker invokes SelectPeers() and returns&lt;br /&gt;
                                                                 //a list of neighbors to that peer&lt;br /&gt;
      void recordPeer(); //record information of a peer when it first connects the tracker or update it when some old&lt;br /&gt;
                                    //information is already stored&lt;br /&gt;
                                   //the information exchanged between a tracker and a peer may be &amp;lt;peerID, videoName&amp;gt;&lt;br /&gt;
                                   // or &amp;lt;peerID, videoName, ip_Address, port&amp;gt; if we want to do simulation on different machines&lt;br /&gt;
    } &lt;br /&gt;
  4. If we really want to send video files between peers, we may need a Storage class to operate with files&lt;br /&gt;
  5. We may design a superclass of all peers, trackers, and neighbors, as a typical networking server to deal with&lt;br /&gt;
      network connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
	<entry>
		<id>https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2586</id>
		<title>Private:psim</title>
		<link rel="alternate" type="text/html" href="https://nmsl.cs.sfu.ca/index.php?title=Private:psim&amp;diff=2586"/>
		<updated>2009-03-05T20:28:27Z</updated>

		<summary type="html">&lt;p&gt;Ysa57: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the development of a discrete event simulator for P2P video streaming applications. This simulator captures important features of data-driven video streaming systems. In particular, it is designed to evaluate: (i) the performance of various segment scheduling algorithms; (ii) the potential of network coding in multi-layer P2P video streaming systems.&lt;br /&gt;
 &lt;br /&gt;
= Class Diagrams =&lt;br /&gt;
&lt;br /&gt;
* use long for time/offset in msec, which has a rollover time 24.85 days&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Frame { // video frame, a layer of it, read from trace file&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    int layer; // layer number it belongs to, set to zero for nonscalable frame&lt;br /&gt;
    long deadlineOffset; // deadline offset compared to the start of the video, in msec&lt;br /&gt;
    int size; // frame size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Segment { // packetized frames&lt;br /&gt;
    int no; // serial number&lt;br /&gt;
    Vector&amp;lt;Frame&amp;gt; frames; // reference to included frame&lt;br /&gt;
    int totalSize; // aggregate size in bytes&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Video { // a media file, shared by a group of peers&lt;br /&gt;
    String filename; // video trace file path and name&lt;br /&gt;
    Hashtable&amp;lt;int, Frame&amp;gt; frameTrace; // frames read from the trace file&lt;br /&gt;
    Hashtable&amp;lt;int, Segment&amp;gt; segmentTrace; // segments generated by the prepareSegments(...)&lt;br /&gt;
    void prepareSegments(int noFrame); // packetize frames into segment, &lt;br /&gt;
        // noFrame indicates how many frames should we put in one segment; &lt;br /&gt;
        // we might implement other packtization schemes later.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Neighbor { // keep track of what my neighbor has done&lt;br /&gt;
    Peer peer; // peer instance, for accessing availability info&lt;br /&gt;
    int estimateRate; // estimated rate (maybe historical)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Peer { // represent a running peer&lt;br /&gt;
    int ingressBW; // incoming bandwidth in bps&lt;br /&gt;
    int egressBW; // outgoing bandwidth in bps&lt;br /&gt;
    BitSet avail; // availability bufmap&lt;br /&gt;
    Vector&amp;lt;Neighbor&amp;gt; neighbors; // peers that we may send requests to &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Group { // peers that have downloaded or want to download a Video&lt;br /&gt;
    Video video; // media shared among peers&lt;br /&gt;
    Vector&amp;lt;Peer&amp;gt; peers; // peers in this group&lt;br /&gt;
    void join(Peer peer); // adding a new peer into this group&lt;br /&gt;
    void leave(Peer peer); // removing a peer from this group&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Connection { // end to end network link between two peers&lt;br /&gt;
    Peer peer1; // one end&lt;br /&gt;
    Peer peer2; // the other&lt;br /&gt;
    long delay; // transmission delay in msec&lt;br /&gt;
    int e2eBW; // end-to-end bandwidth in bps&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// XXX TODO XXX&lt;br /&gt;
&lt;br /&gt;
class SimException {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Interface EventHandler {&lt;br /&gt;
    void handle() throws SimException; // callback function&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Event {&lt;br /&gt;
    long time; // when this event happens&lt;br /&gt;
    Peer src; // which peer generates this event&lt;br /&gt;
    Peer dst; // whom is destinate of this event &lt;br /&gt;
    Vector&amp;lt;EventHandler&amp;gt; handlers; //process an event and update states accordingly&lt;br /&gt;
    int type; // enum, see below&lt;br /&gt;
    // 1. connect: peer 1 makes a connection to peer 2, and add each other into neighbors&lt;br /&gt;
    // 2. requestSent: a receiver sends a high-priority request message to a sender&lt;br /&gt;
    // 3. requestArrived: a request message gets to a sender&lt;br /&gt;
    // 4. dataSent: a sender sends a data segment&lt;br /&gt;
    // 5. dataArrived: a data segment arrives to a receiver&lt;br /&gt;
&lt;br /&gt;
    void addHandler(Interface EventHandler); // add an additional event handler&lt;br /&gt;
    void rmvHandler(Interface EventHandler); // remove an additional event handler&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class EventQueue {&lt;br /&gt;
    SortedMap&amp;lt;Long, Event&amp;gt; queue; // events sorted on its time&lt;br /&gt;
    void dispatch(Event event); // sequentially invoke even handlers &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Simulator {&lt;br /&gt;
    long simTime; // elapsed simulation time in msec&lt;br /&gt;
    EventQueue events; // pending events that will be processed&lt;br /&gt;
    void dispatchEvent(); // forever loop to process the next event&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some comments:&lt;br /&gt;
  1. At the beginning, we should have a peer publish a video (or a trace file).&lt;br /&gt;
  2. The join() and leave() methods in the Group class may be moved to the Peer class and each peer&lt;br /&gt;
    should has a IP address, bitmap field and a listen() method.&lt;br /&gt;
  3. We may add a Tracker class:&lt;br /&gt;
    Class Tracker&lt;br /&gt;
    { &lt;br /&gt;
      URL url; //peers use this url to find the tracker&lt;br /&gt;
      Vector&amp;lt;Peer&amp;gt; peers; //maintain a peer list to be quired by peers&lt;br /&gt;
      Vector&amp;lt;InetAddress&amp;gt; SelectPeers();  //when a peer joins a group at the first time, it quires other peers from the&lt;br /&gt;
                                          //tracker,  then the tracker invokes SelectPeers() and returns&lt;br /&gt;
                                          //a list of neighbors to that peer&lt;br /&gt;
      void recordPeer(); //record information of a peer when it first connects the tracker or update it when some old&lt;br /&gt;
                          //information is already stored&lt;br /&gt;
      //the information exchanged between a tracker and a peer may be &amp;lt;peerID, videoName, ipAddress, port&amp;gt;&lt;br /&gt;
    } &lt;br /&gt;
  4. If we really want to send video files between peers, we may need a Storage class to operate with files&lt;br /&gt;
  5. We may design a superclass of all peers, trackers, and neighbors, as a typical networking server to deal with&lt;br /&gt;
      network connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysa57</name></author>
	</entry>
</feed>