1
1
#!/usr/bin/python
2
2
3
- import os
3
+ # pylint: disable=missing-module-docstring
4
+ # pylint: disable=missing-function-docstring
5
+ # pylint: disable=missing-class-docstring
4
6
7
+ import os
5
8
import shutil
6
- from mininet .topo import Topo
7
- from mininet .node import Host
8
- from mininet .net import Mininet
9
+
9
10
from mininet .cli import CLI
10
- from mininet .util import dumpNodeConnections
11
11
from mininet .link import Link
12
12
from mininet .log import setLogLevel
13
+ from mininet .net import Mininet
14
+ # from mininet.topo import Topo
15
+ from mininet .node import Host
16
+ from mininet .util import dumpNodeConnections
13
17
14
- #BASEDIR = "/home/user/mytests/ospf3routers/nodeconf/"
18
+ # BASEDIR = "/home/user/mytests/ospf3routers/nodeconf/"
15
19
BASEDIR = os .getcwd ()+ "/nodeconf/"
16
20
OUTPUT_PID_TABLE_FILE = "/tmp/pid_table_file.txt"
17
21
18
22
PRIVDIR = '/var/priv'
19
23
24
+
20
25
class BaseNode (Host ):
21
26
22
27
def __init__ (self , name , * args , ** kwargs ):
@@ -25,27 +30,29 @@ def __init__(self, name, *args, **kwargs):
25
30
self .dir = "/tmp/%s" % name
26
31
self .nets = []
27
32
if not os .path .exists (self .dir ):
28
- os .makedirs (self .dir )
33
+ os .makedirs (self .dir )
29
34
30
35
def config (self , ** kwargs ):
36
+ # pylint: disable=arguments-differ
37
+
31
38
# Init steps
32
39
Host .config (self , ** kwargs )
33
40
# Iterate over the interfaces
34
- first = True
41
+ # first = True
35
42
for intf in self .intfs .values ():
36
43
# Remove any configured address
37
- self .cmd ('ifconfig %s 0' % intf .name )
44
+ self .cmd ('ifconfig %s 0' % intf .name )
38
45
# # For the first one, let's configure the mgmt address
39
46
# if first:
40
47
# first = False
41
48
# self.cmd('ip a a %s dev %s' %(kwargs['mgmtip'], intf.name))
42
- #let's write the hostname in /var/mininet/hostname
49
+ # let's write the hostname in /var/mininet/hostname
43
50
self .cmd ("echo '" + self .name + "' > " + PRIVDIR + "/hostname" )
44
- if os .path .isfile (BASEDIR + self .name + "/start.sh" ) :
45
- self .cmd ('source %s' % BASEDIR + self .name + "/start.sh" )
51
+ if os .path .isfile (BASEDIR + self .name + "/start.sh" ):
52
+ self .cmd ('source %s' % BASEDIR + self .name + "/start.sh" )
46
53
47
54
def cleanup (self ):
48
- def remove_if_exists (filename ):
55
+ def remove_if_exists (filename ):
49
56
if os .path .exists (filename ):
50
57
os .remove (filename )
51
58
@@ -86,78 +93,80 @@ def __init__(self, name, *args, **kwargs):
86
93
87
94
# the add_link function creates a link and assigns the interface names
88
95
# as node1-node2 and node2-node1
89
- def add_link (node1 , node2 ):
96
+
97
+
98
+ def add_link (node1 , node2 ):
90
99
Link (node1 , node2 , intfName1 = node1 .name + '-' + node2 .name ,
91
- intfName2 = node2 .name + '-' + node1 .name )
100
+ intfName2 = node2 .name + '-' + node1 .name )
101
+
92
102
93
103
def create_topo (my_net ):
104
+ # pylint: disable=invalid-name
94
105
h1 = my_net .addHost (name = 'h1' , cls = BaseNode )
95
106
h2 = my_net .addHost (name = 'h2' , cls = BaseNode )
96
107
h3 = my_net .addHost (name = 'h3' , cls = BaseNode )
97
108
r1 = my_net .addHost (name = 'r1' , cls = Router )
98
109
r2 = my_net .addHost (name = 'r2' , cls = Router )
99
110
r3 = my_net .addHost (name = 'r3' , cls = Router )
100
111
101
- #note that if the interface names are not provided,
102
- #the order of adding link will determine the
103
- #naming of the interfaces (e.g. on r1: r1-eth0, r1-eth1, r1-eth2...)
112
+ # note that if the interface names are not provided,
113
+ # the order of adding link will determine the
114
+ # naming of the interfaces (e.g. on r1: r1-eth0, r1-eth1, r1-eth2...)
104
115
# it is possible to provide names as follows
105
116
# Link(h1, r1, intfName1='h1-eth0', intfName2='r1-eth0')
106
117
# the add_link function creates a link and assigns the interface names
107
118
# as node1-node2 and node2-node1
108
119
109
- #Link(h1, r1, intfName1='h1-r1', intfName2='r1-h1')
110
- #Link(h2, r2, intfName1='h2-r2', intfName2='r2-h2')
111
- #Link(h3, r3, intfName1='h3-r3', intfName2='r3-h3')
112
- add_link (h1 ,r1 )
113
- add_link (h2 ,r2 )
114
- add_link (h3 ,r3 )
120
+ # Link(h1, r1, intfName1='h1-r1', intfName2='r1-h1')
121
+ # Link(h2, r2, intfName1='h2-r2', intfName2='r2-h2')
122
+ # Link(h3, r3, intfName1='h3-r3', intfName2='r3-h3')
123
+ add_link (h1 , r1 )
124
+ add_link (h2 , r2 )
125
+ add_link (h3 , r3 )
115
126
116
- add_link (r1 ,r2 )
117
- add_link (r1 ,r3 )
118
- add_link (r2 ,r3 )
127
+ add_link (r1 , r2 )
128
+ add_link (r1 , r3 )
129
+ add_link (r2 , r3 )
119
130
120
131
121
- def stopAll ():
132
+ def stop_all ():
122
133
# Clean Mininet emulation environment
123
134
os .system ('sudo mn -c' )
124
135
# Kill all the started daemons
125
136
os .system ('sudo killall sshd zebra ospfd' )
126
137
127
- def extractHostPid (dumpline ):
138
+
139
+ def extract_host_pid (dumpline ):
128
140
temp = dumpline [dumpline .find ('pid=' )+ 4 :]
129
- return int (temp [:len (temp )- 2 ])
141
+ return int (temp [:len (temp )- 2 ])
130
142
131
143
132
-
133
- def simpleTest ():
144
+ def simple_test ():
134
145
"Create and test a simple network"
135
146
136
- #topo = RoutersTopo()
137
- #net = Mininet(topo=topo, build=False, controller=None)
147
+ # topo = RoutersTopo()
148
+ # net = Mininet(topo=topo, build=False, controller=None)
138
149
net = Mininet (topo = None , build = False , controller = None )
139
150
create_topo (net )
140
151
141
152
net .build ()
142
153
net .start ()
143
154
144
-
145
155
print ("Dumping host connections" )
146
156
dumpNodeConnections (net .hosts )
147
- #print "Testing network connectivity"
148
- #net.pingAll()
157
+ # print "Testing network connectivity"
158
+ # net.pingAll()
149
159
150
- with open (OUTPUT_PID_TABLE_FILE ,"w" ) as file :
160
+ with open (OUTPUT_PID_TABLE_FILE , "w" ) as file :
151
161
for host in net .hosts :
152
- file .write ("%s %d\n " % (host , extractHostPid ( repr (host ) )) )
153
-
154
- CLI ( net )
155
- net .stop ()
156
- stopAll ()
162
+ file .write ("%s %d\n " % (host , extract_host_pid (repr (host ))))
157
163
164
+ CLI (net )
165
+ net .stop ()
166
+ stop_all ()
158
167
159
168
160
169
if __name__ == '__main__' :
161
170
# Tell mininet to print useful information
162
171
setLogLevel ('info' )
163
- simpleTest ()
172
+ simple_test ()
0 commit comments