commit is_exclusive flag implementation and e-tree services
[unimgr.git] / resources / create_lan_topology.py
1 #!/usr/bin/python
2
3 """
4   Copyright (c) 2018 Xoriant Corporation and others. All rights reserved.
5  
6   This program and the accompanying materials are made available under 
7   the terms of the Eclipse Public License v1.0 which accompanies this distribution,
8   and is available at http://www.eclipse.org/legal/epl-v10.html
9  
10 """
11
12 import re
13 import sys
14 import os
15 import time
16
17 from mininet.cli import CLI
18 from mininet.log import setLogLevel, info, error
19 from mininet.net import Mininet
20 from mininet.link import Intf
21 from mininet.util import quietRun
22 from mininet.node import Controller, RemoteController
23 from mininet.topo import Topo
24 from mininet.node import Node
25 from mininet.util import waitListening
26 from functools import partial
27 from mininet.node import OVSSwitch
28
29 class PocTopo( Topo ):
30         "Topology prepared for Presto NRP tutorial"
31
32         def __init__( self ):
33
34         # Initialize topology
35                 Topo.__init__( self )
36
37                 # Add hosts and switches
38                 h1 = self.addHost( 'h1' )
39                 h2 = self.addHost( 'h2' )
40                 h3 = self.addHost( 'h3' )
41
42                 s1 = self.addSwitch( 's1' )
43                 s2 = self.addSwitch( 's2' )
44                 s3 = self.addSwitch( 's3' )
45                 s4 = self.addSwitch( 's4' )
46         # Add links
47                 self.addLink( h1, s1 )
48                 self.addLink( h2, s2 )
49                 self.addLink( h3, s3 )
50                 self.addLink( s1, s4 )
51                 self.addLink( s2, s4 )
52                 self.addLink( s3, s4 )
53
54
55 #topos = { 'poctopo': ( lambda: PocTopo() ) }
56
57 if __name__ == '__main__':
58         setLogLevel( 'info' )
59
60         os.system('ovs-vsctl set-manager ptcp:6640')
61
62         defaultIF1 = 'enp0s3'
63         defaultIF2 = 'enp0s8'
64         defaultIF3 = 'enp0s9'
65     #    defaultIF4 = 'enp0s10'
66         defaultControllerIP = '127.0.0.1'
67         defaultInputSwitch = 0
68         defaultOutputSwitch = 1
69
70     # try to get hw intfs from the command line; by default, use eth1 and eth2
71         odl_controller_ip = sys.argv[ 1 ] if len( sys.argv ) > 1 else defaultControllerIP
72         intfName = sys.argv[ 2 ] if len( sys.argv ) > 2 else ""
73         intfName2 = sys.argv[ 3 ] if len( sys.argv ) > 3 else ""
74         intfName3 = sys.argv[ 4 ] if len( sys.argv ) > 4 else ""
75         intfName4 = sys.argv[ 5 ] if len( sys.argv ) > 5 else ""
76         input_switch0 = 0
77         input_switch1 = 1
78         input_switch2 = 2
79      #   input_switch3 = 3
80
81         OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' )
82
83         topo = PocTopo( )
84
85         net = Mininet(topo, switch=OVSSwitch13, controller=partial( RemoteController, ip=odl_controller_ip, port=6633 ) )
86
87         if intfName != "":
88                 switch = net.switches[ input_switch0 ]
89                 info( '*** Adding hardware interface', intfName, 'to switch', switch.name, '\n' )
90                 Intf( intfName, node=switch )
91
92         if intfName2 != "":
93                 switch2 = net.switches[ input_switch1 ]
94                 info( '*** Adding hardware interface', intfName2, 'to switch', switch2.name, '\n' )
95                 Intf(intfName2, node=switch2)
96
97         if intfName3 != "":
98                 switch3 = net.switches[ input_switch2 ]
99                 info( '*** Adding hardware interface', intfName3, 'to switch', switch3.name, '\n' )
100                 Intf(intfName3, node=switch3)
101         
102
103         net.start()
104
105 #       os.system('ovs-ofctl -O OpenFlow13 del-flows s'+str(input_switch+1))
106 #       os.system('ovs-ofctl -O OpenFlow13 del-flows s'+str(output_switch+1))
107         CLI( net )
108         net.stop()