-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.cpp
More file actions
46 lines (43 loc) · 1.24 KB
/
Copy pathnode.cpp
File metadata and controls
46 lines (43 loc) · 1.24 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
#include "node.h"
#pragma once
void node::transmit(string message, int seq_num, string dest_mac_address)
{
dataframe data(message, seq_num, mac_address, dest_mac_address);
if (dest_mac_address == "FF:FF:FF:FF:FF:FF")
{
//FF:FF:FF:FF:FF:FF is the broadcast address.
cout << "Device " << device_id << " broadcasting '" << message << "'" << endl;
}
else
{
cout << "Device " << device_id << " sending '" << message << "' to " << dest_mac_address << endl;
}
for (int i = 0; i < num_links; i++)
{
cout << "Device " << device_id << " sending data to link" << endl;
links[i].transmit(data);
}
}
void node::recieve(dataframe data)
{
bool broadcast = false;
if (data.get_dest_mac_address() == "FF:FF:FF:FF:FF:FF")
{
broadcast = true;
//if destination mac address is the broadcast adress (FF:FF:FF:FF:FF:FF),
//then we make the broadcast flag true.
}
if (data.get_dest_mac_address() == mac_address || broadcast)
{
cout << data.get_message() << " recieved at device " << device_id << endl;
}
}
void node::set_links(link *l, int n)
{
links = l;
num_links = n;
}
string node::get_mac_address()
{
return mac_address;
}