1*2f2c4c7aSAndroid Build Coastguard Worker#!/usr/bin/python3 2*2f2c4c7aSAndroid Build Coastguard Worker# 3*2f2c4c7aSAndroid Build Coastguard Worker# Copyright 2021 The Android Open Source Project 4*2f2c4c7aSAndroid Build Coastguard Worker# 5*2f2c4c7aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*2f2c4c7aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*2f2c4c7aSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*2f2c4c7aSAndroid Build Coastguard Worker# 9*2f2c4c7aSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*2f2c4c7aSAndroid Build Coastguard Worker# 11*2f2c4c7aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*2f2c4c7aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*2f2c4c7aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*2f2c4c7aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*2f2c4c7aSAndroid Build Coastguard Worker# limitations under the License. 16*2f2c4c7aSAndroid Build Coastguard Worker 17*2f2c4c7aSAndroid Build Coastguard Workerimport unittest 18*2f2c4c7aSAndroid Build Coastguard Worker 19*2f2c4c7aSAndroid Build Coastguard Workerimport net_test 20*2f2c4c7aSAndroid Build Coastguard Worker 21*2f2c4c7aSAndroid Build Coastguard Worker 22*2f2c4c7aSAndroid Build Coastguard Workerclass SysctlsTest(net_test.NetworkTest): 23*2f2c4c7aSAndroid Build Coastguard Worker 24*2f2c4c7aSAndroid Build Coastguard Worker def check(self, f): 25*2f2c4c7aSAndroid Build Coastguard Worker with open(f) as algs_file: 26*2f2c4c7aSAndroid Build Coastguard Worker algs = algs_file.readline().strip().split(' ') 27*2f2c4c7aSAndroid Build Coastguard Worker bad_algs = [a for a in algs if a not in ['bbr', 'cubic', 'reno']] 28*2f2c4c7aSAndroid Build Coastguard Worker msg = ("Obsolete TCP congestion control algorithm found. These " 29*2f2c4c7aSAndroid Build Coastguard Worker "algorithms will decrease real-world networking performance for " 30*2f2c4c7aSAndroid Build Coastguard Worker "users and must be disabled. Found: %s" % bad_algs) 31*2f2c4c7aSAndroid Build Coastguard Worker self.assertEqual(bad_algs, [], msg) 32*2f2c4c7aSAndroid Build Coastguard Worker 33*2f2c4c7aSAndroid Build Coastguard Worker @unittest.skipUnless(net_test.LINUX_VERSION >= (5, 7, 0), "not yet namespaced") 34*2f2c4c7aSAndroid Build Coastguard Worker def testAllowedCongestionControl(self): 35*2f2c4c7aSAndroid Build Coastguard Worker self.check('/proc/sys/net/ipv4/tcp_allowed_congestion_control') 36*2f2c4c7aSAndroid Build Coastguard Worker 37*2f2c4c7aSAndroid Build Coastguard Worker @unittest.skipUnless(net_test.LINUX_VERSION >= (5, 7, 0), "not yet namespaced") 38*2f2c4c7aSAndroid Build Coastguard Worker def testAvailableCongestionControl(self): 39*2f2c4c7aSAndroid Build Coastguard Worker self.check('/proc/sys/net/ipv4/tcp_available_congestion_control') 40*2f2c4c7aSAndroid Build Coastguard Worker 41*2f2c4c7aSAndroid Build Coastguard Worker def testCongestionControl(self): 42*2f2c4c7aSAndroid Build Coastguard Worker self.check('/proc/sys/net/ipv4/tcp_congestion_control') 43*2f2c4c7aSAndroid Build Coastguard Worker 44*2f2c4c7aSAndroid Build Coastguard Worker 45*2f2c4c7aSAndroid Build Coastguard Workerif __name__ == "__main__": 46*2f2c4c7aSAndroid Build Coastguard Worker unittest.main() 47