network-simulator/netsim/include/Device.hpp

39 lines
891 B
C++
Raw Normal View History

2023-06-29 23:13:55 +00:00
#pragma once
#include <cstdint>
2023-07-01 12:39:27 +00:00
#include <array>
2023-06-29 23:13:55 +00:00
#include <string>
#include <memory>
2023-07-02 11:53:56 +00:00
class Port;
2023-06-29 23:13:55 +00:00
class Device {
public:
friend std::ostream& operator<<(std::ostream& os, const Device& device);
public:
Device(const std::string& macAddress);
2023-07-01 12:39:27 +00:00
Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f);
2023-07-02 16:24:59 +00:00
inline static std::shared_ptr<Device> Create(const std::string& macAddress) {
2023-07-01 12:39:27 +00:00
return std::make_shared<Device>(macAddress);
}
2023-07-02 16:24:59 +00:00
inline static std::shared_ptr<Device> Create() {
2023-07-01 12:39:27 +00:00
return std::make_shared<Device>(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256);
}
2023-06-29 23:13:55 +00:00
2023-07-02 16:24:59 +00:00
void Connect(std::shared_ptr<Device> other);
2023-07-02 16:32:14 +00:00
void Send();
void Receive();
2023-06-29 23:13:55 +00:00
private:
void parseAndSetMac(const std::string& macAddress);
2023-07-02 11:53:56 +00:00
private:
std::shared_ptr<Port> port;
2023-06-30 18:47:50 +00:00
public:
2023-06-29 23:13:55 +00:00
uint8_t macAddress[6];
};