GlobalBpiLib  1.0
Port.h
1 /*
2  * Port.h
3  *
4  * Author: Valentin Fitz
5  * Institute: University of Duisburg-Essen, Germany
6  */
7 
8 #ifndef PROTOCOLS_PORT_H_
9 #define PROTOCOLS_PORT_H_
10 
11 #include <pthread.h>
12 #include <string>
13 #include <vector>
14 #include <pcap.h>
15 #include <linux/if_packet.h>
16 #include <sys/socket.h>
17 #include <arpa/inet.h>
18 
19 #include "../GlobalBpiLib.hpp"
20 #include "MessageTypes.h"
21 
22 class ProtocolLogic;
23 
27 class Port {
28 public:
29  Port(int id, ProtocolLogic* proto);
30 
33  int rxMsg, txMsg;
35  virtual ~Port();
36  void start();
37  void stop();
38  void addMessage(EthernetMessage* msg);
39  void setNeighbour(char* mac);
40  char* getRawMacAddress();
41  char* getRawDestMacAddress();
42  std::string getLocalMacAddr();
43  int getPortId();
44  void setLinkSpeed(double d);
46 private:
47  pthread_t _egrPort;
48  pthread_t _ingPort;
49  pthread_mutex_t _mutex;
50  pthread_cond_t _cond;
51  int _portId;
52  std::string _devName;
53  bool active = true;
54  char error_buffer[PCAP_ERRBUF_SIZE];
55  char source_mac[6];
56  char destination_mac[6];
57  pcap_t *pcap_port = nullptr;
58  std::vector<EthernetMessage*> _msgQueue;
59  int raw_port = -1;
60  struct sockaddr_ll raw_port_address;
61  ProtocolLogic* protocol;
62  struct timeval lasttval;
63  double transmissionSpeed = 5;
65  static void * _egrPortThreadEntryFunction(void * This);
66  static void * _ingPortThreadEntryFunction(void * This);
67  void _startEgrPortThread();
68  void _startIngPortThread();
69  static void _packetHandlerCallback(u_char *user, const struct pcap_pkthdr* pkthdr, const u_char* packet);
70  void _packetHandler(const struct pcap_pkthdr* pkthdr, const u_char* packet);
71  void _setupPcapListener();
72  void _setupRawSocket();
73  void _retrieveMacAddress();
75 protected:
76  virtual bool _handleIncomingPaket(EthernetMessage* msg);
77  virtual bool _handleOutgoingPaket(EthernetMessage* msg);
78  virtual bool _handleIncomingPaketFI(EthernetMessage* msg);
79  virtual bool _handleOutgoingPaketFI(EthernetMessage* msg);
80 };
81 
82 #endif /* PROTOCOLS_PORT_H_ */
Represents an BananaPi R1 ethernet port, starting an ingress port (pcap listener) as well as an egres...
Definition: Port.h:27
Custom bpi printer class.
Definition: GlobalBpiLib.hpp:41
std::string getLocalMacAddr()
Definition: Port.cpp:63
virtual bool _handleOutgoingPaketFI(EthernetMessage *msg)
Definition: PortEgress.cpp:100
char * getRawDestMacAddress()
Definition: Port.cpp:86
void setLinkSpeed(double d)
Definition: Port.cpp:90
void stop()
Definition: Port.cpp:44
void addMessage(EthernetMessage *msg)
Definition: PortEgress.cpp:89
Default implementation of the logic of a protocol implementation.
Definition: ProtocolLogic.h:22
int getPortId()
Definition: Port.cpp:82
int txMsg
Definition: Port.h:33
BpiOutStream bpierr
Definition: Port.h:32
void setNeighbour(char *mac)
Definition: Port.cpp:55
char * getRawMacAddress()
Definition: Port.cpp:51
virtual bool _handleIncomingPaketFI(EthernetMessage *msg)
Definition: PortIngress.cpp:91
virtual bool _handleIncomingPaket(EthernetMessage *msg)
Definition: PortIngress.cpp:87
virtual bool _handleOutgoingPaket(EthernetMessage *msg)
Definition: PortEgress.cpp:96
BpiOutStream bpiout
Definition: Port.h:31
Ethernet v2 message type.
Definition: MessageTypes.h:56