This shows you the differences between two versions of the page.
rl:labs:02:contents:01 [2013/10/06 00:12] mihai.carabas [01. Pupularea tabelei de comutare] |
rl:labs:02:contents:01 [2023/10/17 10:51] (current) vlad_iulius.nastase [01. [10p] Implementare Hub] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== 01. Popularea tabelei de comutare ==== | + | ==== 01. [15p] Implementare Hub ==== |
- | * tutorial de comutare: o topologie cu switch și 4 stații | + | 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: |
- | * se dă "ping" în PT și se urmărește tabela de comunutare | + | |
- | * se curăță tabela de comutare și se urmărește popularea ei | + | |
+ | <code> | ||
+ | while hub is powered on: | ||
+ | for each port: | ||
+ | if there is incoming data: | ||
+ | read the incoming data | ||
+ | for each other port: | ||
+ | send the data to that port | ||
+ | </code> | ||
+ | |||
+ | 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]]. 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> | ||
+ | # data este de tip byte array | ||
+ | interface, data, length = recv_from_any_link() | ||
+ | send_to_link(interface, data, length) | ||
+ | </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> |