Skip to content

Commit 2957bfb

Browse files
committed
Added Documentation
Update AUTHORS file Update Copyright year fixed the codestyle Addded pcn-packetcapture test description Added comments
1 parent 8558c59 commit 2957bfb

15 files changed

Lines changed: 262 additions & 130 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ The following people, in alphabetical order, have either authored or signed
22
off on commits in the Polycube repository:
33

44
Aasif Shaikh aasif@shaikh.cc
5+
Davide Antonino Giorgio davideantonino94@gmail.com
56
Francesco Messina francescomessina92@hotmail.com
67
Fulvio Risso fulvio.risso@polito.it
78
Gianluca Scopelliti gianlu.1033@gmail.com
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
Packetcapture service
2+
=====================
3+
4+
Packetcapture is a transparent service that allows to capture packets flowing through the interface it is attached to, apply (simple) filters and obtain capture in *.pcap* format. In particular, the service supports either saving captured packets in the local filesystem (e.g., useful in case of high network traffic) or it can interact and deliver packets to a remote client that stores them in the remote filesystem.
5+
6+
An example of a client that uses the REST api of the packetcapture service is available in '*Packetcapture_Client*' directory.
7+
8+
Features
9+
--------
10+
- Transparent service, can be attached to any interface of any Polycube service
11+
- Support for (simple) IPv4 filters: source prefix, destination prefix, source port, destination port and layer 4 protocol.
12+
- Support partial capture of packets (i.e., snaplen)
13+
- Support localmode (store data locally) or network mode (send packets to a remote client) operations
14+
15+
Limitations
16+
-----------
17+
- No IPv6 filtering
18+
- Traffic is returned as is, without any anonimization primitive.
19+
20+
How to use
21+
----------
22+
The packetcapture service is a transparent service, it can be attached to a cube port.
23+
24+
Create the service
25+
^^^^^^^^^^^^^^^^^^
26+
27+
::
28+
29+
#create the packetcapture service
30+
polycubectl packetcapture add sniffer capture=bidirectional
31+
32+
This service can operate in four working modes (actually, the forth mode is just to turn the capture off):
33+
34+
- capture only incoming packets: **capture=ingress**
35+
- capture only outgoing packets: **capture=egress**
36+
- capture both incoming and outgoing packets: **capture=bidirectional**
37+
- turn packet capture off: **capture=off**
38+
39+
*capture* option indicates the direction of the packets that the service must capture.
40+
The direction of the captured packets is independent of the operation in "nework mode" or "non network mode".
41+
42+
In this example the service named '*mysniffer*' will work in bidirectional mode.
43+
44+
45+
Attach to a cube port
46+
^^^^^^^^^^^^^^^^^^^^^
47+
::
48+
49+
# Attach the service to a cube port
50+
polycubectl attach mysniffer br1:toveth1
51+
52+
Now the packetcapture service is attached to the port *toveth1* of the bridge *br1*
53+
54+
+----------+
55+
veth1 ---**x**-| br1 |------ veth2
56+
+----------+
57+
58+
59+
Filters
60+
-------
61+
Traffic can be selected by means of the following filters:
62+
63+
- source prefix
64+
- destination prefix
65+
- source port
66+
- destination port
67+
- later 4 protocol
68+
69+
Source prefix filter
70+
^^^^^^^^^^^^^^^^^^^^
71+
::
72+
73+
# Example of the source prefix filter
74+
polycubectl mysniffer filters set src=10.10.10.10/24
75+
76+
Destination prefix filter
77+
^^^^^^^^^^^^^^^^^^^^^^^^^
78+
::
79+
80+
# Example of the destination prefix filter
81+
polycubectl mysniffer filters set dst=10.10.10.10/24
82+
83+
Source port filter
84+
^^^^^^^^^^^^^^^^^^
85+
::
86+
87+
# Example of the source port filter
88+
polycubectl mysniffer filters set sport=80
89+
90+
Destination port filter
91+
^^^^^^^^^^^^^^^^^^^^^^^
92+
::
93+
94+
# Example of the destination port filter
95+
polycubectl mysniffer filters set dport=80
96+
97+
Layer 4 protocol filter
98+
^^^^^^^^^^^^^^^^^^^^^^^
99+
::
100+
101+
# Example of the layer 4 protocol filter
102+
polycubectl mysniffer filters set l4proto=tcp
103+
104+
Snaplen filter
105+
^^^^^^^^^^^^^^
106+
::
107+
108+
# Example of the snaplen filter
109+
# In this case we capture only the first 80 bytes of each packet
110+
polycubectl mysniffer filters set snaplen=80
111+
112+
113+
Filters can be viewed using the command **polycubectl mysniffer filters show**
114+
115+
Get the capture dump
116+
--------------------
117+
When the service is not set in *networkmode*, the dump is automatically written in a resilient way in the current working directory.
118+
119+
The path of the capture file can be shown using the command: **polycubectl mysniffer show dump**
120+
121+
Otherwise, if the service is set in network mode, the capture file can be requested through the use of the provided Python client, or queried simply through the service API.
122+
123+
How to use the demo client
124+
^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
::
126+
127+
# Start the client script
128+
python3 client.py <IPv4 address> <file destination name>
129+
130+
131+
Set network mode
132+
^^^^^^^^^^^^^^^^
133+
::
134+
135+
# Start sniffer in network mode
136+
polycubectl mysniffer set networkmode=true
137+
138+
# Start sniffer in local model
139+
polycubectl mysniffer set networkmode=false

src/services/pcn-packetcapture/cmake/LoadFileAsVariable.cmake

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/services/pcn-packetcapture/src/Filters.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ uint32_t Filters::getSnaplen() {
6161
void Filters::setSnaplen(const uint32_t &value) {
6262
snaplen = value;
6363
set_snaplen = true;
64-
if(!bootstrap)
64+
if (!bootstrap)
6565
parent_.updateFiltersMaps();
6666
}
6767

@@ -78,10 +78,9 @@ void Filters::setSrc(const std::string &value) {
7878
inet_pton(AF_INET, source_ip.data(), &ip_src_filter);
7979
ip_src_filter = ntohl(ip_src_filter);
8080
networkSrc = ip_src_filter & netmaskSrc;
81-
//network_packet = pkt_values.srcIp & netmask_filter; //TODO: do it in the fast path
8281

8382
set_srcIp = true;
84-
if(!bootstrap)
83+
if (!bootstrap)
8584
parent_.updateFiltersMaps();
8685
}
8786

@@ -98,10 +97,9 @@ void Filters::setDst(const std::string &value) {
9897
inet_pton(AF_INET, source_ip.data(), &ip_dst_filter);
9998
ip_dst_filter = ntohl(ip_dst_filter);
10099
networkDst = ip_dst_filter & netmaskDst;
101-
//network_packet = pkt_values.dstIp & netmask_filter; //TODO: do it in the fast path
102100

103101
set_dstIp = true;
104-
if(!bootstrap)
102+
if (!bootstrap)
105103
parent_.updateFiltersMaps();
106104
}
107105

@@ -110,13 +108,14 @@ std::string Filters::getL4proto() {
110108
}
111109

112110
void Filters::setL4proto(const std::string &value) {
113-
if((value.compare(std::string("tcp")) == 0) || (value.compare(std::string("udp")) == 0)){
111+
if ((value.compare(std::string("tcp")) == 0) || (value.compare(std::string("udp")) == 0)){
114112
l4proto = value;
115113
set_l4proto = true;
116-
if(!bootstrap)
114+
if (!bootstrap)
117115
parent_.updateFiltersMaps();
118-
}else
116+
} else {
119117
throw std::runtime_error("Bad value at setL4proto. Please enter 'tcp' or 'udp'");
118+
}
120119
}
121120

122121
uint16_t Filters::getSport() {
@@ -126,7 +125,7 @@ uint16_t Filters::getSport() {
126125
void Filters::setSport(const uint16_t &value) {
127126
srcPort = value;
128127
set_srcPort = true;
129-
if(!bootstrap)
128+
if (!bootstrap)
130129
parent_.updateFiltersMaps();
131130
}
132131

@@ -137,22 +136,22 @@ uint16_t Filters::getDport() {
137136
void Filters::setDport(const uint16_t &value) {
138137
dstPort = value;
139138
set_dstPort = true;
140-
if(!bootstrap)
139+
if (!bootstrap)
141140
parent_.updateFiltersMaps();
142141
}
143142

144-
uint32_t Filters::getNetworkFilterSrc(){
143+
uint32_t Filters::getNetworkFilterSrc() {
145144
return networkSrc;
146145
}
147146

148-
uint32_t Filters::getNetworkFilterDst(){
147+
uint32_t Filters::getNetworkFilterDst() {
149148
return networkDst;
150149
}
151150

152-
uint32_t Filters::getNetmaskFilterSrc(){
151+
uint32_t Filters::getNetmaskFilterSrc() {
153152
return netmaskSrc;
154153
}
155154

156-
uint32_t Filters::getNetmaskFilterDst(){
155+
uint32_t Filters::getNetmaskFilterDst() {
157156
return netmaskDst;
158157
}

src/services/pcn-packetcapture/src/Filters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/services/pcn-packetcapture/src/Globalheader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/services/pcn-packetcapture/src/Globalheader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/services/pcn-packetcapture/src/Packet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,10 +89,10 @@ std::string ascii_to_utf8(const std::vector<uint8_t> &packet){
8989
std::string ret("");
9090
char ch;
9191

92-
for(int i = 0 ; i < packet.size(); i++){
93-
if(packet[i] < 128){
92+
for (int i = 0 ; i < packet.size(); i++){
93+
if (packet[i] < 128){
9494
ret.push_back((char) packet[i]);
95-
}else{
95+
} else {
9696
ch = (char) packet[i];
9797
ret.push_back((char)((packet[i] >> 6) | 0xC0));
9898
ret.push_back((ch & 0x3F) | 0x80);

src/services/pcn-packetcapture/src/Packet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/services/pcn-packetcapture/src/Packetcapture-lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The Polycube Authors
2+
* Copyright 2019 The Polycube Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)