bcc/python: remove unused imports, remove redundant semicolon
[platform/upstream/bcc.git] / src / python / bcc / tcp.py
1 # Copyright 2018 Netflix, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # from include/net/tcp_states.h:
16 tcpstate = {}
17 tcpstate[1] = 'ESTABLISHED'
18 tcpstate[2] = 'SYN_SENT'
19 tcpstate[3] = 'SYN_RECV'
20 tcpstate[4] = 'FIN_WAIT1'
21 tcpstate[5] = 'FIN_WAIT2'
22 tcpstate[6] = 'TIME_WAIT'
23 tcpstate[7] = 'CLOSE'
24 tcpstate[8] = 'CLOSE_WAIT'
25 tcpstate[9] = 'LAST_ACK'
26 tcpstate[10] = 'LISTEN'
27 tcpstate[11] = 'CLOSING'
28 tcpstate[12] = 'NEW_SYN_RECV'
29
30 # from include/net/tcp.h:
31 TCPHDR_FIN = 0x01
32 TCPHDR_SYN = 0x02
33 TCPHDR_RST = 0x04
34 TCPHDR_PSH = 0x08
35 TCPHDR_ACK = 0x10
36 TCPHDR_URG = 0x20
37 TCPHDR_ECE = 0x40
38 TCPHDR_CWR = 0x80
39
40 def flags2str(flags):
41     arr = []
42     if flags & TCPHDR_FIN:
43         arr.append("FIN")
44     if flags & TCPHDR_SYN:
45         arr.append("SYN")
46     if flags & TCPHDR_RST:
47         arr.append("RST")
48     if flags & TCPHDR_PSH:
49         arr.append("PSH")
50     if flags & TCPHDR_ACK:
51         arr.append("ACK")
52     if flags & TCPHDR_URG:
53         arr.append("URG")
54     if flags & TCPHDR_ECE:
55         arr.append("ECE")
56     if flags & TCPHDR_CWR:
57         arr.append("CWR")
58     return "|".join(arr)