-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathFiveTuple.cpp
110 lines (88 loc) · 1.84 KB
/
FiveTuple.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "FiveTuple.h"
namespace FeatureExtractor {
FiveTuple::FiveTuple()
: ip_proto(PROTO_ZERO), src_ip(0), dst_ip(0), src_port(0), dst_port(0)
{
}
FiveTuple::~FiveTuple()
{
}
ip_field_protocol_t FiveTuple::get_ip_proto() const
{
return ip_proto;
}
void FiveTuple::set_ip_proto(ip_field_protocol_t ip_proto)
{
this->ip_proto = ip_proto;
}
uint32_t FiveTuple::get_src_ip() const
{
return src_ip;
}
void FiveTuple::set_src_ip(uint32_t src_ip)
{
this->src_ip = src_ip;
}
uint32_t FiveTuple::get_dst_ip() const
{
return dst_ip;
}
void FiveTuple::set_dst_ip(uint32_t dst_ip)
{
this->dst_ip = dst_ip;
}
uint16_t FiveTuple::get_src_port() const
{
return src_port;
}
void FiveTuple::set_src_port(uint16_t src_port)
{
this->src_port = src_port;
}
uint16_t FiveTuple::get_dst_port() const
{
return dst_port;
}
void FiveTuple::set_dst_port(uint16_t dst_port)
{
this->dst_port = dst_port;
}
bool FiveTuple::land() const
{
return (src_ip == dst_ip && src_port == dst_port);
}
bool FiveTuple::operator<(const FiveTuple& other) const
{
if (ip_proto < other.ip_proto)
return true;
if (ip_proto > other.ip_proto)
return false;
// IP protocols are same
if (src_ip < other.src_ip)
return true;
if (src_ip > other.src_ip)
return false;
// src IPs are equal
if (dst_ip < other.dst_ip)
return true;
if (dst_ip > other.dst_ip)
return false;
// dst IPs are equal
if (src_port < other.src_port)
return true;
if (src_port > other.src_port)
return false;
// src ports are equal
return (dst_port < other.dst_port);
}
FiveTuple FiveTuple::get_reversed() const
{
FiveTuple tuple;
tuple.ip_proto = this->ip_proto;
tuple.src_ip = this->dst_ip;
tuple.dst_ip = this->src_ip;
tuple.src_port = this->dst_port;
tuple.dst_port = this->src_port;
return tuple;
}
}