-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a selftest for tcpbpf (sock_ops) that checks that the appropriate callbacks occured and that it can access tcp_sock fields and that their values are correct. Run with command: ./test_tcpbpf_user Adding the flag "-d" will show why it did not pass. Signed-off-by: Lawrence Brakmo <brakmo@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Lawrence Brakmo
authored and
Alexei Starovoitov
committed
Jan 26, 2018
1 parent
d448749
commit d6d4f60
Showing
8 changed files
with
480 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python2 | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
|
||
import sys, os, os.path, getopt | ||
import socket, time | ||
import subprocess | ||
import select | ||
|
||
def read(sock, n): | ||
buf = '' | ||
while len(buf) < n: | ||
rem = n - len(buf) | ||
try: s = sock.recv(rem) | ||
except (socket.error), e: return '' | ||
buf += s | ||
return buf | ||
|
||
def send(sock, s): | ||
total = len(s) | ||
count = 0 | ||
while count < total: | ||
try: n = sock.send(s) | ||
except (socket.error), e: n = 0 | ||
if n == 0: | ||
return count; | ||
count += n | ||
return count | ||
|
||
|
||
serverPort = int(sys.argv[1]) | ||
HostName = socket.gethostname() | ||
|
||
# create active socket | ||
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) | ||
try: | ||
sock.connect((HostName, serverPort)) | ||
except socket.error as e: | ||
sys.exit(1) | ||
|
||
buf = '' | ||
n = 0 | ||
while n < 1000: | ||
buf += '+' | ||
n += 1 | ||
|
||
sock.settimeout(1); | ||
n = send(sock, buf) | ||
n = read(sock, 500) | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python2 | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
|
||
import sys, os, os.path, getopt | ||
import socket, time | ||
import subprocess | ||
import select | ||
|
||
def read(sock, n): | ||
buf = '' | ||
while len(buf) < n: | ||
rem = n - len(buf) | ||
try: s = sock.recv(rem) | ||
except (socket.error), e: return '' | ||
buf += s | ||
return buf | ||
|
||
def send(sock, s): | ||
total = len(s) | ||
count = 0 | ||
while count < total: | ||
try: n = sock.send(s) | ||
except (socket.error), e: n = 0 | ||
if n == 0: | ||
return count; | ||
count += n | ||
return count | ||
|
||
|
||
SERVER_PORT = 12877 | ||
MAX_PORTS = 2 | ||
|
||
serverPort = SERVER_PORT | ||
serverSocket = None | ||
|
||
HostName = socket.gethostname() | ||
|
||
# create passive socket | ||
serverSocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) | ||
host = socket.gethostname() | ||
|
||
try: serverSocket.bind((host, 0)) | ||
except socket.error as msg: | ||
print 'bind fails: ', msg | ||
|
||
sn = serverSocket.getsockname() | ||
serverPort = sn[1] | ||
|
||
cmdStr = ("./tcp_client.py %d &") % (serverPort) | ||
os.system(cmdStr) | ||
|
||
buf = '' | ||
n = 0 | ||
while n < 500: | ||
buf += '.' | ||
n += 1 | ||
|
||
serverSocket.listen(MAX_PORTS) | ||
readList = [serverSocket] | ||
|
||
while True: | ||
readyRead, readyWrite, inError = \ | ||
select.select(readList, [], [], 2) | ||
|
||
if len(readyRead) > 0: | ||
waitCount = 0 | ||
for sock in readyRead: | ||
if sock == serverSocket: | ||
(clientSocket, address) = serverSocket.accept() | ||
address = str(address[0]) | ||
readList.append(clientSocket) | ||
else: | ||
sock.settimeout(1); | ||
s = read(sock, 1000) | ||
n = send(sock, buf) | ||
sock.close() | ||
serverSocket.close() | ||
sys.exit(0) | ||
else: | ||
print 'Select timeout!' | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#ifndef _TEST_TCPBPF_H | ||
#define _TEST_TCPBPF_H | ||
|
||
struct tcpbpf_globals { | ||
__u32 event_map; | ||
__u32 total_retrans; | ||
__u32 data_segs_in; | ||
__u32 data_segs_out; | ||
__u32 bad_cb_test_rv; | ||
__u32 good_cb_test_rv; | ||
__u64 bytes_received; | ||
__u64 bytes_acked; | ||
}; | ||
#endif |
Oops, something went wrong.