-
Notifications
You must be signed in to change notification settings - Fork 0
/
topo-gtp.py
executable file
·112 lines (90 loc) · 3.82 KB
/
topo-gtp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
# Copyright 2019-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.node import Host
from mininet.topo import Topo
from stratum import StratumBmv2Switch
CPU_PORT = 255
class IPv4Host(Host):
"""Host that can be configured with an IPv4 gateway (default route).
"""
def config(self, mac=None, ip=None, defaultRoute=None, lo='up', gw=None,
**_params):
super(IPv4Host, self).config(mac, ip, defaultRoute, lo, **_params)
self.cmd('ip -4 addr flush dev %s' % self.defaultIntf())
self.cmd('ip -6 addr flush dev %s' % self.defaultIntf())
self.cmd('sysctl -w net.ipv4.ip_forward=0')
self.cmd('ip -4 link set up %s' % self.defaultIntf())
self.cmd('ip -4 addr add %s dev %s' % (ip, self.defaultIntf()))
if gw:
self.cmd('ip -4 route add default via %s' % gw)
# Disable offload
for attr in ["rx", "tx", "sg"]:
cmd = "/sbin/ethtool --offload %s %s off" % (
self.defaultIntf(), attr)
self.cmd(cmd)
def updateIP():
return ip.split('/')[0]
self.defaultIntf().updateIP = updateIP
class TutorialTopo(Topo):
"""2x2 fabric topology for GTP encap exercise with 2 IPv4 hosts emulating an
enodeb (base station) and a gateway to a Packet Data Metwork (PDN)
"""
def __init__(self, *args, **kwargs):
Topo.__init__(self, *args, **kwargs)
# Leaves
# gRPC port 50001
leaf1 = self.addSwitch('leaf1', cls=StratumBmv2Switch, cpuport=CPU_PORT)
# gRPC port 50002
leaf2 = self.addSwitch('leaf2', cls=StratumBmv2Switch, cpuport=CPU_PORT)
# Spines
# gRPC port 50003
spine1 = self.addSwitch('spine1', cls=StratumBmv2Switch, cpuport=CPU_PORT)
# gRPC port 50004
spine2 = self.addSwitch('spine2', cls=StratumBmv2Switch, cpuport=CPU_PORT)
# Switch Links
self.addLink(spine1, leaf1)
self.addLink(spine1, leaf2)
self.addLink(spine2, leaf1)
self.addLink(spine2, leaf2)
# IPv4 hosts attached to leaf 1
enodeb = self.addHost('enodeb', cls=IPv4Host, mac='00:00:00:00:00:10',
ip='10.0.100.1/24', gw='10.0.100.254')
self.addLink(enodeb, leaf1) # port 3
# IPv4 hosts attached to leaf 2
pdn = self.addHost('pdn', cls=IPv4Host, mac='00:00:00:00:00:20',
ip='10.0.200.1/24', gw='10.0.200.254')
self.addLink(pdn, leaf2) # port 3
def main():
net = Mininet(topo=TutorialTopo(), controller=None)
net.start()
CLI(net)
net.stop()
print '#' * 80
print 'ATTENTION: Mininet was stopped! Perhaps accidentally?'
print 'No worries, it will restart automatically in a few seconds...'
print 'To access again the Mininet CLI, use `make mn-cli`'
print 'To detach from the CLI (without stopping), press Ctrl-D'
print 'To permanently quit Mininet, use `make stop`'
print '#' * 80
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Mininet topology script for 2x2 fabric with stratum_bmv2 and IPv4 hosts')
args = parser.parse_args()
setLogLevel('info')
main()