aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.h
blob: 14159b48201f5d47f947d9193d9efec5648198a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef DIST_VECTOR_H
#define DIST_VECTOR_H

#include "linked_list.h"
#include "network_addr.h"
#include "config.h"

/* Item of the distance vector. 
 * If <<reachable>> is set to 0, then it means that the network is reachable.
 * If <<reachable>> has positive value, then it indicates that the network was
 * unreachable for <<reachable>> turns.
 */
struct vector_item {
  struct network_addr network;
  struct in_addr      via_ip;
  uint16_t            distance;
  uint8_t             reachable;
  bool                is_connected_directly;
};

/* Initis distance vector with given neighbours array. */
void init_dv(list_t *dv, int n_cnt, struct network_addr *neighbours);

/* Returns true if given distance vector item is connected directly, false otherwise. */
bool is_connected_directly(struct vector_item item);

/* Updates the distance vector. */
void update_dv_new_item(list_t *distance_vector, struct vector_item new_item);

/* Updates reachabilities. */
void update_dv_reachability(list_t *distance_vector);

/* Print distance vector. */
void print_dv(list_t *distance_vector);

#endif