blob: d3f59410a1b907f396611fcfff178e53ad23d8c6 [file] [log] [blame]
Andrea Campanella715a4c42022-06-01 15:39:46 +02001#!/usr/bin/python
2
3# SPDX-FileCopyrightText: 2022-present Intel Corporation
4# SPDX-License-Identifier: Apache-2.0
5
6import argparse
7
8from mininet.cli import CLI
9from mininet.log import setLogLevel
10from mininet.net import Mininet
11from mininet.topo import Topo
12from stratum import StratumBmv2Switch
13
14from mn_lib import IPv4Host
15from mn_lib import TaggedIPv4Host
16
17CPU_PORT = 255
18
19
20class TutorialTopo(Topo):
21 """2x2 fabric topology with IPv4 hosts"""
22
23 def __init__(self, *args, **kwargs):
24 Topo.__init__(self, *args, **kwargs)
25
26 # Leaves
27 # gRPC port 50001
28 leaf1 = self.addSwitch('leaf1', cls=StratumBmv2Switch, cpuport=CPU_PORT)
29 # gRPC port 50002
30 leaf2 = self.addSwitch('leaf2', cls=StratumBmv2Switch, cpuport=CPU_PORT)
31
32 # Spines
33 # gRPC port 50003
34 spine1 = self.addSwitch('spine1', cls=StratumBmv2Switch, cpuport=CPU_PORT)
35 # gRPC port 50004
36 spine2 = self.addSwitch('spine2', cls=StratumBmv2Switch, cpuport=CPU_PORT)
37
38 # Switch Links
39 self.addLink(spine1, leaf1)
40 self.addLink(spine1, leaf2)
41 self.addLink(spine2, leaf1)
42 self.addLink(spine2, leaf2)
43
44 # IPv4 hosts attached to leaf 1
45 h1a = self.addHost('h1a', cls=IPv4Host, mac="00:00:00:00:00:1A",
46 ip='172.16.1.1/24', gw='172.16.1.254')
47 h1b = self.addHost('h1b', cls=IPv4Host, mac="00:00:00:00:00:1B",
48 ip='172.16.1.2/24', gw='172.16.1.254')
49 h1c = self.addHost('h1c', cls=TaggedIPv4Host, mac="00:00:00:00:00:1C",
50 ip='172.16.1.3/24', gw='172.16.1.254', vlan=100)
51 h2 = self.addHost('h2', cls=TaggedIPv4Host, mac="00:00:00:00:00:20",
52 ip='172.16.2.1/24', gw='172.16.2.254', vlan=200)
53 self.addLink(h1a, leaf1) # port 3
54 self.addLink(h1b, leaf1) # port 4
55 self.addLink(h1c, leaf1) # port 5
56 self.addLink(h2, leaf1) # port 6
57
58 # IPv4 hosts attached to leaf 2
59 h3 = self.addHost('h3', cls=TaggedIPv4Host, mac="00:00:00:00:00:30",
60 ip='172.16.3.1/24', gw='172.16.3.254', vlan=300)
61 h4 = self.addHost('h4', cls=IPv4Host, mac="00:00:00:00:00:40",
62 ip='172.16.4.1/24', gw='172.16.4.254')
63 self.addLink(h3, leaf2) # port 3
64 self.addLink(h4, leaf2) # port 4
65
66
67def main():
68 net = Mininet(topo=TutorialTopo(), controller=None)
69 net.start()
70 CLI(net)
71 net.stop()
72
73
74if __name__ == "__main__":
75 parser = argparse.ArgumentParser(
76 description='Mininet topology script for 2x2 fabric with stratum_bmv2 and IPv4 hosts')
77 args = parser.parse_args()
78 setLogLevel('info')
79
80 main()