This shows you the differences between two versions of the page.
|
rl:labs:02:contents:01 [2023/10/02 16:20] vlad_andrei.badoiu |
rl:labs:02:contents:01 [2023/10/17 10:51] (current) vlad_iulius.nastase [01. [10p] Implementare Hub] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== 00. [10p] Implementare Hub ==== | + | ==== 01. [15p] Implementare Hub ==== |
| - | Vom implementa in Python funcționalitatea de baza a unui Hub. Cum am vazut si in cadrul exercitiului anterior, pentru fiecare frame primit, hub-ul îl trimite pe toate interfețele (link sau port). Mai jos gasim o descriere in pseudocod: | + | Vom implementa in Python funcționalitatea de baza a unui Hub. Cum am vazut si in cadrul laboratorului anterior, pentru fiecare frame primit, hub-ul îl trimite pe toate interfețele (link sau port). Mai jos gasim o descriere in pseudocod: |
| <code> | <code> | ||
| Line 13: | Line 13: | ||
| In acest exercițiu vom implementa un Hub in Python pornind de la un API simplu de primire si trimitere de frame-uri Ethernet. Vom porni | In acest exercițiu vom implementa un Hub in Python pornind de la un API simplu de primire si trimitere de frame-uri Ethernet. Vom porni | ||
| - | de la scheletul de la [[https://gitlab.cs.pub.ro/rl/schelet-hub|urmatoarea adresa]]. Implementarea se va face in **hub.py**, in dreptul celor doua TODO-uri. | + | de la scheletul de la [[https://gitlab.cs.pub.ro/rl/schelet-hub|urmatoarea adresa]]. Tot acolo, gasiti in **README.md** detalii despre rularea scheletului. Implementarea se va face in **hub.py**, in dreptul celor doua TODO-uri. |
| <code Python> | <code Python> | ||
| Line 20: | Line 20: | ||
| send_to_link(interface, data, length) | send_to_link(interface, data, length) | ||
| </code> | </code> | ||
| + | |||
| + | <hidden> | ||
| + | <code Python> | ||
| + | def main(): | ||
| + | interfaces = range(0, wrapper.init() + 1) | ||
| + | |||
| + | while True: | ||
| + | interface, data, length = recv_from_any_link() | ||
| + | | ||
| + | print("Received frame of size {} on interface {}".format(length, interface)) | ||
| + | |||
| + | for i in interfaces: | ||
| + | if i != interface: | ||
| + | print("Forwarding to interface {}".format(i)) | ||
| + | send_to_link(i, data, length) | ||
| + | </code> | ||
| + | </hidden> | ||