-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.h
More file actions
87 lines (66 loc) · 1.39 KB
/
Copy pathbridge.h
File metadata and controls
87 lines (66 loc) · 1.39 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<vector>
#include<iostream>
#include<map>
#include<string>
#define st string
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define vst vector<st>
using namespace std;
class Message{
public:
st root_belief;
int root_dist;
st sender;
st lan_name;
Message(st rb, int d, st s, st l);
};
class Lan{
public:
st name;
vector<st> bridges; // neighbour bridges
int root_dist;
st designated_bridge;
Lan(st n, vector<st> bs);
bool update(Message m);
};
class Packet{
public:
st sender_host;
st dest_host;
st lan_name;
st sender_bridge;
Packet(st s, st d, st l, st b){
sender_host = s;
dest_host = d;
lan_name = l;
sender_bridge = b;
}
void print(){
cout<<"Packet "<<sender_host<<" to "<<dest_host;
cout<<" is at lan "<<lan_name<<" and was sent by ";
cout<<sender_bridge<<endl;
}
};
struct host_compare{
bool operator()(const st &a, const st &b) const {
int aa = stoi(a.substr(1,a.size()-1));
int bb = stoi(b.substr(1,b.size()-1));
return aa < bb;
}
};
class Bridge{
public:
st id;
vector<st> ports; // same as neighbour lans
map<st,st> port_type;
st root_belief;
int root_dist;
st parent_bridge;
map<st,st,host_compare> ftable; // host to port
Bridge(st idd, vector<st> portss);
bool update(Message m, bool trace, int time);
vector<Message> send_message(bool trace, int time);
void print_ftable();
vector<Packet> send_packet(Packet p);
};