Difference between revisions of "Private:psim"

From NMSL
 
(7 intermediate revisions by the same user not shown)
Line 16: Line 16:
 
| 1.5
 
| 1.5
 
| Cheng
 
| Cheng
|  
+
| March 18, 2009
|  
+
| March 18, 2009
 
|-
 
|-
 
| Finalize the simulator engine
 
| Finalize the simulator engine
Line 35: Line 35:
 
| Yuanbin
 
| Yuanbin
 
| March 18, 2009
 
| March 18, 2009
|
+
| March 18, 2009
 
|}
 
|}
  
= Class Diagrams =
+
= High-Level Design =
 
 
* use long for time/offset in msec, which has a rollover time 24.85 days
 
 
 
<pre>
 
 
 
class Layer { // video layer, we divide each layer into fixed size blocks, we keep track of
 
                    // block size and no blocks here
 
    int layer; // layer number it belongs to, set to zero for nonscalable frame
 
    int blockSize; // blocks are fixed size, in bytes
 
    int noBlocks; // how many block here
 
    int dataSize; // aggregate size of all blocks
 
}
 
 
 
class Frame { // video frame, read from trace file
 
    int no; // serial number
 
    long deadlineOffset; // deadline offset compared to the start of the video, in msec
 
    int totalSize; // total frame size in bytes, including all layers
 
}
 
 
 
class Segment { // packetized frames
 
    int no; // serial number
 
    Vector<Frame> frames; // reference to included frame
 
    int totalSize; // aggregate size in bytes
 
    Hashtable<Integer, Layer> layers; // reference to layers of this frame, key is the layer id
 
    long getDeadline(); // returns the worst case deadline of this segment (first frame?)
 
}
 
 
 
class Video { // a media file, shared by a group of peers
 
    String filename; // video trace file path and name
 
    Hashtable<int, Frame> frameTrace; // frames read from the trace file
 
    Hashtable<int, Segment> segmentTrace; // segments generated by the prepareSegments(...)
 
    void prepareSegments(int noFrame); // packetize frames into segment,
 
        // noFrame indicates how many frames should we put in one segment;
 
        // we might implement other packtization schemes later.
 
}
 
 
 
Interface Node { // a network node, currently can be either a tracker or a peer
 
}
 
                       
 
class Tracker implement Node { // holds a set of groups/videos
 
    Vector<Group> groups; // all the video groups
 
    void addPeer(Group group, Peer peer); // insert a peer into a video group
 
}
 
 
 
class Peer implements Node { // represent a running peer
 
    int id; // sequential peer id
 
    int ingressBW; // incoming bandwidth in bps
 
    int egressBW; // outgoing bandwidth in bps
 
    Hashtable<Video, Vector<Connection>> senders; // peers that we may send requests to
 
    Hashtable<Video, Vector<Connection>> receivers; // peers that we may send data to
 
    Connection tracker; // control connection to the tracker
 
    Hashtable<Video, VideoBufMap> vBufMaps; // points to the video-level buffer map
 
    void join(Video vide); // the peer joins a group
 
    void leave(Video video); //the peer leaves the group
 
    //here we should call a scheduling algorithm to do the scheduling
 
    void start(Video video); // start downloading a video
 
    void stop(Video video); // stop downloading
 
}
 
 
 
class Group { // peers that have downloaded or want to download a Video
 
    Video video; // media shared among peers
 
    Vector<Peer> peers; // peers in this group
 
    Vector<Peer> join(Peer peer); // adding a new peer into this group, and return a list of senders
 
    void leave(Peer peer); // removing a peer from this group
 
}
 
 
 
class Connection { // end to end network link between two peers
 
    Peer peer1; // one end
 
    Peer peer2; // the other
 
    long delay; // transmission delay in msec
 
    int e2eBW; // end-to-end bandwidth in bps
 
    int estimateRate; // estimated rate (maybe historical)
 
}
 
 
 
class VideoBufMap {
 
    Hashtable<Integer, SegBufMap> sBufMaps; // points to segment bufmap
 
}
 
 
 
class SegBufMap {
 
    Hashtable<Integer, LayerBufMap> lBufMaps; // points to layer bufmap
 
}
 
 
 
class LayerBufMap {
 
    boolean avail; // availability bit for this (video, segment, layer) tuple
 
    NCBuf ncBuf; // network coding structure
 
}
 
 
 
class NCBuf {
 
    boolean servCapibility; // Serving capability of each segment
 
                                      // show whether this segment is capable of serving other peers(applicable in NC)
 
    int noCodedBl; //  No. of encoded blocks for this (video,segment,layer)
 
    BufferedMatrix matrix; // coefficients and their corresponding encoded blocks up to now
 
}
 
 
 
class BufferedMatrix{ // save coefficients and their corresponding encoded blocks up to now
 
    Vector<Vector<Integer>> coef; // coefficients of the corresponding encoded blocks
 
    Vector <Integer>encodedValue; // encoded blocks
 
    Vector<Integer> decode(); // perform decoding process and return the original blocks of a segment
 
    void encode(); // perform encoding process on blocks of a segment
 
   
 
}
 
 
 
class SysParam{ // system parameters that can be changed in each iteration of the simulation
 
    float portionServ; // after receiving this portion of coded blocks out of total number of blocks, the segment is capable 
 
                                  of serving to others [in case of network coding]
 
    long skipSec; // time duration which is skipped from the current playback point for a new joined peer [in case of
 
                            network coding]
 
    float portionEncoding; // a given peer peform encoding among this portion of encoded blocks out of the total coded
 
                                        blocks that has been received so far
 
                                    // blocks for encoding will be chosen randomly out of all received encoded blocks [in case of 
 
                                        network coding]
 
}
 
 
 
// the following classes implement the Galois field [in case of network coding]
 
// coefficients should be selected randomly from Galois field
 
class ExtendedGaloisField extends GaloisField { // extension of Galois field where you can create 
 
                                                                    //the field with a predefined base and power
 
    GaloisPolynomial[] alfaPowers;
 
    GaloisPolynomial moduloPoly;
 
    char alfa;
 
    GaloisField base;
 
    int pwr;
 
}
 
 
 
public class GaloisField { // implementing the Galois field
 
}
 
 
 
class GaloisPolynomial { //working with Polynomials
 
    private int[] coefs; // coefs are selected from Galois field
 
    private char alfa;
 
    private GaloisField field;
 
}
 
 
 
class GaloisException{
 
}
 
   
 
// XXX TODO XXX
 
 
 
class SlidingWindow{ // the sliding window which contains all the segments that the receiver is interested currently
 
                                  // set it to a fixed size, for example 1 minute of videos
 
                                    // the receiver first inform all its neighbors which part of the video it is interested currently,
 
                                    // then its neighbors will send their bitmap of that part to the receiver for scheduling
 
  int startOffset;        //the offset of the starting segment compared with the start of the video
 
  int endOffset;          // the offset of the ending segment compared with the start of the video
 
  double slidingWindowSize(); //get the size of the sliding window
 
}
 
 
 
class exchangeWindow{ // the exchange window is the front part of the sliding window.
 
                                      //The unavailable segments in exchange window will be requested by the peer
 
                                      //usually we set it to a fixed size, for example, 10 seconds of video
 
                                      // the field of this class is similar to that of the SlidingWindow class
 
  int startOffset;
 
  int endOffset;
 
  void move();          // move the exchange window forward afte a scheduling period and do a next scheduling
 
  double getSlidingWindowSize()
 
}
 
 
 
interface Scheduler{ // any class wants to do scheduling should implement this interface
 
  void schedule() throws simException; // the scheduling period is specified in the specific scheduling algorithm class
 
}
 
 
 
class resultItem{ //this class records a scheduling item
 
  int peerID;
 
  int segID;
 
  long startTime; //start time of the peer to transmit this segment
 
}
 
 
 
class SchedulingResult{                // this class is used to record scheduling results and do some statistics,
 
                                                      // for example, calculate the average delivery rate
 
  Vector<resultItem> item;    // result item: <peerID, segID, startTime> (we may write this vector to a log file later)
 
  long runningTime;                  //running time of the algorithm
 
  long deliveryRatio;                //Average delivery ratio
 
 
 
  double getDeliveryRatio();  //get the actual  average delivery ratio
 
  double getRunningTime(); //get the running time
 
}
 
 
 
class SEFF implements Scheduler{ // the Serial Earliest Finish-time First scheduling algorithm
 
  SchedulingResult result;                // create a schedulingResult object to store the result
 
 
 
  void schedule();                                  //implement the Scheduler interface
 
  void writeResult();  //write scheduling result to the result object of one scheduling period
 
                                                              //including calculating the average delivery ratio and running time
 
}
 
 
 
class LRF implements Scheduler{ // the Local Rarest First algorithm
 
  SchedulingResult result;                // create a schedulingResult object to store the result
 
 
 
  void schedule();                                  //implement the Scheduler interface
 
  void writeResult();  //write scheduling result to the result object of one scheduling period
 
                                                              //including calculating the average delivery ratio and running time
 
}
 
 
 
 
 
  
class RndGen { // common random number/event generators, to deal with
+
We present the high level design of the pSim. Please find a coarse class diagram below, and the source file can be downloaded [[media:psim.dia|here]].
                      // 1. event: add new receiver for a group/video
 
                      // 2. event: remove a receiver from a group/video
 
                      // 3. number: peer's bandwidth
 
}
 
  
class SimException {
+
[[Image:psim.png|center|640px]]
  
}
 
  
Interface EventHandler {
 
    void handle() throws SimException; // callback function
 
}
 
  
class Event {
+
Some misc notes:
    long time; // when this event happens
+
* We use long for time/offset in msec, which has a rollover time 24.85 days
    Node src; // which peer generates this event
 
    Node dst; // whom is destinate of this event
 
    Vector<EventHandler> handlers; //process an event and update states accordingly
 
    int type; // enum, see below
 
    // 1. connectSent: peer 1 makes a connection to peer 2, and add each other into neighbors
 
    // 2. connectArrived: the connect message is received by the peer 2
 
    // 3. acceptSent: the potential sender reply with an accept message
 
    // 4. acceptArrived: the accept message arrives at the connection originator
 
    // 5. requestSent: a receiver sends a high-priority request message to a sender
 
    // 6. requestArrived: a request message gets to a sender
 
    // 7. dataSent: a sender sends a data segment
 
    // 8. dataArrived: a data segment arrives to a receiver
 
    // 9. joinSent: a join message to the tracker
 
    // 10. joinArrived: a join message reaches the tracker
 
    // 11. responseSent: a response message sent by the tracker
 
    // 12. responseArrived: a response message reaches the receiver
 
 
 
    // 13. scheduleStarted: a scheduling period started.
 
    //14. bimapSyncSent: the receiver inform all its neighbors what part of the video it is interested currently
 
                                          in order to get a small bitmap from them to do scheduleing, this message is sent
 
                                            when the receiver: jumps to view another part of the video or a new neighbor joins.  
 
    //15. bitmapSyncArrived: the sender receives the bitmap Synchronization information
 
  
    //commet: how should we do when a scheduling period expires?
+
=== System Architecture ===
    //There are two situations: 1. all scheduled segments arrived; 2. some segments are still in transmission.
+
The core of the simulator is a simulation engine that is abstracted as the
 +
'''Simulator''' class. Since pSim is a discrete event simulator, the
 +
'''Simulator''' class keeps track of a moving simulation time '''simTime''',
 +
which is different from the wall clock (real-time). '''Simulator''' consists of
 +
an '''EventQueue''' that provides the interface of push and pop an event from a
 +
priority queue of the pending events. The pending events are sorted on the
 +
event time in the ascending order. '''Simulator''' works as the follows, in
 +
'''dispatchEvents''' method, the next event is popped from '''EventQueue'''.
 +
'''Simulator''' then update '''simTime''' and calls '''dispatch''' method to
 +
process that event using method '''dispatch''', and then drop the processed
 +
event away. '''Simulator''' then popped the next event from '''EventQueue'''
 +
and update '''simTime'''. That is, the method '''dispatchEvent''' is a forever
 +
loop, thus the caller must not expect '''dispatchEvent''' to return.
  
    void addHandler(Interface EventHandler); // add an additional event handler
+
Other components in pSim add new events to '''Simulator''' by calling its
    void rmvHandler(Interface EventHandler); // remove an additional event handler
+
'''push''' method. The new events are pushed through '''EventQueue''' to
}
+
'''CalendarQueue'''. '''CalendarQueue''' is an efficient implementation of
 +
priority queue, which achieves constant time complexity. We implement the
 +
Dynamic Calendar Queue (DCQ) based on a Berkeley implementation, which sort the
 +
pending events on their '''time'''. We notice that we keep '''EventQueue'''
 +
between '''Simulator''' and '''CalendarQueue''', in case we need to switch to
 +
other priority queue implementation such as standard '''TreeMap'''.
  
class EventQueue {
+
In addition to '''EventQueue''', '''Simulator''' also consists of: (i)
    SortedMap<Long, Event> queue; // events sorted on its time
+
'''Logger''' that is responsible for filtering and saving logging messages,
    void dispatch(Event event); // sequentially invoke even handlers
+
(ii) '''RndGen''' that is the system-wide random number generator, and (iii)
}
+
'''SysParam''' that has all system parameters.
  
class Simulator {
+
=== Event and Event Handler ===
    long simTime; // elapsed simulation time in msec
+
Since '''Simulator''' class is driven by its priority queue of events, every
    EventQueue events; // pending events that will be processed
+
'''Event''' must consist of enough information on how to process that
    void dispatchEvent(); // forever loop to process the next event
+
'''Event'''. The main fields of '''Event''' include: '''type''' that is the
}
+
event type, and '''time''' that is the event time. Moreover, the '''Event'''
 +
class maintains a vector of '''EventHandler''' interface, which specifies how
 +
to process that '''Event''''. There is only an abstract method defined in
 +
'''EventHandler''', which is its '''handle''' function. The '''handle
 +
function''' returns a log entry in '''String''' format. We note that this
 +
String must use pipe as the field delimiter, and should not contain any CR nor
 +
LF. See existing code for other convention of the log entries. Notice that,
 +
each '''Event''' instance has no '''EventHandler''' initially: the class who
 +
creates an '''Event''' must provide one or more '''EventHandler''' by calling
 +
the method '''addHandler'''. Last, we mention that the '''dispatch''' method of
 +
'''Simulator''' retrieves all '''EventHandler''' by calling method
 +
'''getHandlers'''.
  
 +
'''Event''' has two subclasses: '''PeerEvent''' is for events that is local to
 +
a peer, e.g., a peer joins a video group is a '''PeerEvent''';
 +
'''NetworkEvent''' is for sending messages between two peers, e.g., a receiver
 +
sends a '''CONNECTMSG''' to a sender. '''PeerEvent''' has two fields:
 +
'''Peer''' and '''Video'''. '''NetworkEvent''' has four fields: (i) '''conn'''
 +
that captures the connection status between two peers, (ii) '''length''' that
 +
describes the length of this message, (iii) '''direction''' that indicates
 +
whether the message is sent from receiver to sender or not, and (iv)
 +
'''arrived''' shows whether the message has arrived at the destination. More
 +
precisely, a '''NetworkEvent''' is created with '''arrived''' value set to off,
 +
which means that event just enter the connection '''conn'''.  Following the
 +
bandwidth defined in '''conn''', we can compute when will the event arrives at
 +
the destination. This computation is done in '''tHandler''' that stands for
 +
transmission handler. The transmission handler processes a '''NetworkEvent'''
 +
as follows. First, it computes and updates the event time to be the time that
 +
event arrives at the destination. Second, it sets '''arrived''' to be true.
 +
Third, it pushes the same '''NetworkEvent''' back to '''EventQueue'''.
  
  
Some comments:
+
=== Random Number Generator and Profiles ===
*
 
 
 
  
 +
TODO
  
</pre>
 
  
 
= Performance metrics for scheduling =
 
= Performance metrics for scheduling =

Latest revision as of 21:19, 24 March 2009

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.

Todo List

We keep a short todo list here. For each todo item, we also list the expected workload, the current assignee, the tentative due date, and the completion time.

Description Workload (ppl-day) Assignee Tentative Duedate Completion time
Reread and implement Meng Zhang's algorithm 1.5 Cheng March 18, 2009 March 18, 2009
Finalize the simulator engine 1 Cheng March 17, 2009 March 17, 2009
Generalize the scheduling algorithm for multiple layer problem 3 N/A
Reorganize the evaluation setup subsection 2 Yuanbin March 18, 2009 March 18, 2009

High-Level Design

We present the high level design of the pSim. Please find a coarse class diagram below, and the source file can be downloaded here.


Some misc notes:

  • We use long for time/offset in msec, which has a rollover time 24.85 days

System Architecture

The core of the simulator is a simulation engine that is abstracted as the Simulator class. Since pSim is a discrete event simulator, the Simulator class keeps track of a moving simulation time simTime, which is different from the wall clock (real-time). Simulator consists of an EventQueue that provides the interface of push and pop an event from a priority queue of the pending events. The pending events are sorted on the event time in the ascending order. Simulator works as the follows, in dispatchEvents method, the next event is popped from EventQueue. Simulator then update simTime and calls dispatch method to process that event using method dispatch, and then drop the processed event away. Simulator then popped the next event from EventQueue and update simTime. That is, the method dispatchEvent is a forever loop, thus the caller must not expect dispatchEvent to return.

Other components in pSim add new events to Simulator by calling its push method. The new events are pushed through EventQueue to CalendarQueue. CalendarQueue is an efficient implementation of priority queue, which achieves constant time complexity. We implement the Dynamic Calendar Queue (DCQ) based on a Berkeley implementation, which sort the pending events on their time. We notice that we keep EventQueue between Simulator and CalendarQueue, in case we need to switch to other priority queue implementation such as standard TreeMap.

In addition to EventQueue, Simulator also consists of: (i) Logger that is responsible for filtering and saving logging messages, (ii) RndGen that is the system-wide random number generator, and (iii) SysParam that has all system parameters.

Event and Event Handler

Since Simulator class is driven by its priority queue of events, every Event must consist of enough information on how to process that Event. The main fields of Event include: type that is the event type, and time that is the event time. Moreover, the Event class maintains a vector of EventHandler interface, which specifies how to process that Event'. There is only an abstract method defined in EventHandler, which is its handle function. The handle function returns a log entry in String format. We note that this String must use pipe as the field delimiter, and should not contain any CR nor LF. See existing code for other convention of the log entries. Notice that, each Event instance has no EventHandler initially: the class who creates an Event must provide one or more EventHandler by calling the method addHandler. Last, we mention that the dispatch method of Simulator retrieves all EventHandler by calling method getHandlers.

Event has two subclasses: PeerEvent is for events that is local to a peer, e.g., a peer joins a video group is a PeerEvent; NetworkEvent is for sending messages between two peers, e.g., a receiver sends a CONNECTMSG to a sender. PeerEvent has two fields: Peer and Video. NetworkEvent has four fields: (i) conn that captures the connection status between two peers, (ii) length that describes the length of this message, (iii) direction that indicates whether the message is sent from receiver to sender or not, and (iv) arrived shows whether the message has arrived at the destination. More precisely, a NetworkEvent is created with arrived value set to off, which means that event just enter the connection conn. Following the bandwidth defined in conn, we can compute when will the event arrives at the destination. This computation is done in tHandler that stands for transmission handler. The transmission handler processes a NetworkEvent as follows. First, it computes and updates the event time to be the time that event arrives at the destination. Second, it sets arrived to be true. Third, it pushes the same NetworkEvent back to EventQueue.


Random Number Generator and Profiles

TODO


Performance metrics for scheduling

Here are some performance metrics:

  1. Average delivery ratio: number of on-time scheduled segments over total number of segments to be scheduled
  2. Load balance among senders
  3. Initial buffering time
  4. Time and space complexity of the scheduling algorithm


Performance metrics for network coding

Here are some performance metrics:

  1. Playback quality (PSNR)
  2. Resilience to peer dynamics (ability of maintaning good streaming quality)
  3. Required server capacity


How to install uml and svn tools in eclipse3.2.x

  • Install emul2
    1. Go to "http://www.soyatec.com/euml2/installation/", download its free edition. (Select the right version according to your eclipse)
    2. Unpack the zip file
    3. Open your eclipse, and go to Help -> Software Updates -> Find and install ... -> Search for new features to install -> New local site then find the unpakced file to install it.
    4. How to use: after you creating a new java project, go to File -> New -> Other, select the "UML2 Class Diagram" under the eUML directory, then you can create a class diagram for your project .


  • Install subclipse
    1. Open your eclipse, and go to Help -> Software Updates -> Find and install ... -> Search for new features to install -> New Remote Site
    2. Add "http://subclipse.tigris.org/update_1.4.x" to the URL field and add an arbitrary name to the Name field
    3. Follow the instruction to install it.
    4. If you encounter an error like "Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in "org.eclipse.mylyn.tasks.core (3.0.0)" don't worry, just deselect the "Integrations" item and continue to install.
    5. Go to Window -> Preferences -> Team. If you can see SVN under the Team tab, congratulations, your installation is done.
    6. How to use: right click the project you want to commit, select Tean -> Share project -> SVN, input the URL of your svn server, then you can import your project to it.
    7. For more details on how to use subclipse, please refer to http://www.ibm.com/developerworks/opensource/library/os-ecl-subversion/


The project directory

I've put the psim project to "https://cs-svn.cs.surrey.sfu.ca/svn/nsl/schedule/psim". You can check it out in eclipse with subclipse.