예제 #1
0
class Stfq(SchedulingAlgorithm):
    """Start-Time Fair Queuing (STFQ)"""

    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()

        self._last_finish = {}
        self._virt_time = 0

    def get_rank(self, item):
        """Rank the items by their start time, which we calculate from the
        finish time of the last packet.
        """
        flow_id = item.flow
        if flow_id in self._last_finish:
            rank = max(self._virt_time, self._last_finish[flow_id])
        else:
            rank = self._virt_time
        self._last_finish[flow_id] = rank + item.length
        return rank

    def enqueue(self, ref, item):
        rank = self.get_rank(item)
        self._pifo.enqueue(ref, rank)

    def dequeue(self):
        return self._pifo.dequeue()

    def dump(self):
        self._pifo.dump()
예제 #2
0
class Wfq(SchedulingAlgorithm):
    """Weighted Fair Queueing (WFQ)"""
    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()
        self._last_finish = {}
        self._virt_time = 0

    def get_rank(self, item):
        """Rank the items by their start time, which we calculate from the
        finish time of the last packet. However, we divide the packet's length
        with weights to prioritize them. We determine the weights by splitting
        the flow-ids into odd and even numbers.
        """
        flow = item.flow
        weight = 50 if flow % 2 == 1 else 100
        if flow in self._last_finish:
            rank = max(self._virt_time, self._last_finish[flow])
        else:
            rank = self._virt_time
        self._last_finish[flow] = rank + item.length / weight
        return rank

    def enqueue(self, ref, item):
        rank = self.get_rank(item)
        self._pifo.enqueue(ref, rank)

    def dequeue(self):
        return self._pifo.dequeue()

    def dump(self):
        self._pifo.dump()
예제 #3
0
    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()
        self._flow_tracker = FlowTracker()

        self._remains = {}

        # We cheat by accessing the global packet list directly
        for pkt in pkts:
            if pkt.flow in self._remains.keys():
                self._remains[pkt.flow] += pkt.length
            else:
                self._remains[pkt.flow] = pkt.length
예제 #4
0
class Fifo(SchedulingAlgorithm):
    """First in, first out (FIFO)"""
    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()

    def get_rank(self, _):
        """Rank the items in FIFO order."""
        return self._pifo.qlen

    def enqueue(self, ref, item):
        rank = self.get_rank(item)
        self._pifo.enqueue(ref, rank)

    def dequeue(self):
        return self._pifo.dequeue()

    def dump(self):
        self._pifo.dump()
예제 #5
0
class Srpt(SchedulingAlgorithm):
    """Shortest Remaining Processing Time"""
    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()
        self._flow_tracker = FlowTracker()

        self._remains = {}

        # We cheat by accessing the global packet list directly
        for pkt in pkts:
            if pkt.flow in self._remains.keys():
                self._remains[pkt.flow] += pkt.length
            else:
                self._remains[pkt.flow] = pkt.length

    def get_rank(self, item):
        """Rank the items by their remaining total flow length."""

        rank = self._remains[item.flow]
        self._remains[item.flow] -= item.length
        return rank

    def enqueue(self, ref, item):
        flow = self._flow_tracker.enqueue(item)
        rank = self.get_rank(item)
        self._pifo.enqueue(flow, rank)

    def dequeue(self):
        flow = self._pifo.dequeue()
        item = None
        if flow is not None:
            item = flow.dequeue()
        return item

    def dump(self):
        self._pifo.dump()
예제 #6
0
    def __init__(self, name=None):
        super().__init__(name)
        self._pifo = Pifo()

        self._last_finish = {}
        self._virt_time = 0
예제 #7
0
 def __init__(self, name=None):
     super().__init__(name)
     self._pifo = Pifo()