1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

test-network: add tests for L2TP

This commit is contained in:
Yu Watanabe 2019-03-12 17:11:24 +09:00
parent 3a27af62b5
commit cff83db917
4 changed files with 143 additions and 1 deletions

View File

@ -0,0 +1,7 @@
[Match]
Name=test1
[Network]
Address=192.168.30.100/24
IPv6AcceptRA=false
L2TP=l2tp99

View File

@ -0,0 +1,20 @@
[NetDev]
Kind=l2tp
Name=l2tp99
[L2TP]
TunnelId=10
PeerTunnelId=12
Local=static
Remote=192.168.30.101
EncapsulationType=ip
[L2TPSession]
SessionId=25
PeerSessionId=26
Name=l2tp-ses3
[L2TPSession]
SessionId=27
PeerSessionId=28
Name=l2tp-ses4

View File

@ -0,0 +1,25 @@
[NetDev]
Kind=l2tp
Name=l2tp99
[L2TP]
TunnelId=10
PeerTunnelId=11
UDPSourcePort=3000
UDPDestinationPort=4000
Local=static
Remote=192.168.30.101
EncapsulationType=udp
UDPCheckSum=true
UDP6CheckSumRx=true
UDP6CheckSumTx=true
[L2TPSession]
SessionId=15
PeerSessionId=16
Name=l2tp-ses1
[L2TPSession]
SessionId=17
PeerSessionId=18
Name=l2tp-ses2

View File

@ -108,6 +108,14 @@ class Utilities():
subprocess.call(['ip', 'link', 'del', 'dev', link])
time.sleep(1)
def l2tp_tunnel_remove(self, tunnel_ids):
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel']).rstrip().decode('utf-8')
for tid in tunnel_ids:
words='Tunnel ' + tid + ', encap'
if words in output:
subprocess.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid])
time.sleep(1)
def read_ipv6_sysctl_attr(self, link, attribute):
with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f:
return f.readline().strip()
@ -580,7 +588,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
self.assertTrue(self.link_exits('ipiptun99'))
def test_vxlan(self):
self.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
self.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network', '11-dummy.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('vxlan99'))
@ -598,6 +606,88 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'remcsumrx')
self.assertRegex(output, 'gbp')
class NetworkdL2TPTests(unittest.TestCase, Utilities):
links =[
'l2tp-ses1',
'l2tp-ses2',
'l2tp-ses3',
'l2tp-ses4',
'test1']
units = [
'11-dummy.netdev',
'25-l2tp-dummy.network',
'25-l2tp-ip.netdev',
'25-l2tp-udp.netdev']
l2tp_tunnel_ids = [ '10' ]
def setUp(self):
self.l2tp_tunnel_remove(self.l2tp_tunnel_ids)
self.link_remove(self.links)
def tearDown(self):
self.l2tp_tunnel_remove(self.l2tp_tunnel_ids)
self.link_remove(self.links)
self.remove_unit_from_networkd_path(self.units)
@expectedFailureIfModuleIsNotAvailable('l2tp_eth')
def test_l2tp_udp(self):
self.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('test1'))
self.assertTrue(self.link_exits('l2tp-ses1'))
self.assertTrue(self.link_exits('l2tp-ses2'))
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Tunnel 10, encap UDP")
self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101")
self.assertRegex(output, "Peer tunnel 11")
self.assertRegex(output, "UDP source / dest ports: 3000/4000")
self.assertRegex(output, "UDP checksum: enabled")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 15 in tunnel 10")
self.assertRegex(output, "Peer session 16, tunnel 11")
self.assertRegex(output, "interface name: l2tp-ses1")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 17 in tunnel 10")
self.assertRegex(output, "Peer session 18, tunnel 11")
self.assertRegex(output, "interface name: l2tp-ses2")
@expectedFailureIfModuleIsNotAvailable('l2tp_ip')
def test_l2tp_ip(self):
self.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('test1'))
self.assertTrue(self.link_exits('l2tp-ses3'))
self.assertTrue(self.link_exits('l2tp-ses4'))
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Tunnel 10, encap IP")
self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101")
self.assertRegex(output, "Peer tunnel 12")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 25 in tunnel 10")
self.assertRegex(output, "Peer session 26, tunnel 12")
self.assertRegex(output, "interface name: l2tp-ses3")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 27 in tunnel 10")
self.assertRegex(output, "Peer session 28, tunnel 12")
self.assertRegex(output, "interface name: l2tp-ses4")
class NetworkdNetWorkTests(unittest.TestCase, Utilities):
links = [
'bond199',