Skip to content

Commit ecdca49

Browse files
committed
Split pifo-basic into pifo_fifo and pifo_stfq
I decided to split the pifo-basic.py file into two separate packet scheduling files. The program prints the added packets which are already in FIFO order. Therefore, I don't see a point in including the FIFO output as well in the examples.
1 parent ff4458f commit ecdca49

File tree

3 files changed

+97
-55
lines changed

3 files changed

+97
-55
lines changed

queue-exp/pifo-basic.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

queue-exp/pifo_fifo.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# coding: utf-8 -*-
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
#
6+
# pifo-fifo.py
7+
8+
__copyright__ = """
9+
Copyright (c) 2021, Toke Høiland-Jørgensen <[email protected]>
10+
Copyright (c) 2021, Frey Alfredsson <[email protected]>
11+
"""
12+
13+
__license__ = """
14+
This program is free software: you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 3 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
"""
27+
28+
from pifo_lib import Packet, Runner, Pifo
29+
30+
31+
class Fifo(Pifo):
32+
def get_rank(self, item):
33+
return self.qlen
34+
35+
if __name__ == "__main__":
36+
pkts = [
37+
Packet(flow=1, idn=1, length=2),
38+
Packet(flow=1, idn=2, length=2),
39+
Packet(flow=2, idn=1, length=1),
40+
Packet(flow=2, idn=2, length=1),
41+
Packet(flow=2, idn=3, length=1),
42+
]
43+
Runner(pkts, Fifo()).run()

queue-exp/pifo_stfq.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# coding: utf-8 -*-
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
#
6+
# pifo-stfq.py
7+
8+
__copyright__ = """
9+
Copyright (c) 2021 Toke Høiland-Jørgensen <[email protected]>
10+
Copyright (c) 2021 Frey Alfredsson <[email protected]>
11+
"""
12+
13+
__license__ = """
14+
This program is free software: you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 3 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
"""
27+
28+
from pifo_lib import Packet, Runner, Pifo
29+
30+
31+
class Stfq(Pifo):
32+
def __init__(self):
33+
super().__init__()
34+
self.last_finish = {}
35+
self.virt_time = 0
36+
37+
def get_rank(self, pkt):
38+
flow = pkt.flow
39+
if flow in self.last_finish:
40+
rank = max(self.virt_time, self.last_finish[flow])
41+
else:
42+
rank = self.virt_time
43+
self.last_finish[flow] = rank + pkt.length
44+
return rank
45+
46+
if __name__ == "__main__":
47+
pkts = [
48+
Packet(flow=1, idn=1, length=2),
49+
Packet(flow=1, idn=2, length=2),
50+
Packet(flow=2, idn=1, length=1),
51+
Packet(flow=2, idn=2, length=1),
52+
Packet(flow=2, idn=3, length=1),
53+
]
54+
Runner(pkts, Stfq()).run()

0 commit comments

Comments
 (0)