Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2014-10-29 13:04:27 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
88dbd49542981785261b4ea5d084dcd346aa6785
88dbd495
1 parent
6fa17532
Updated optical.py to allow parametrized topologies.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
11 deletions
tools/test/topos/optical-topo.py → tools/test/topos/optical.py
tools/test/topos/optical
-topo
.py
→
tools/test/topos/optical.py
View file @
88dbd49
#!/usr/bin/env python
''' file:
custom/
optical.py '''
''' file: optical.py '''
from
mininet.topo
import
Topo
from
mininet.node
import
RemoteController
from
mininet.net
import
Mininet
from
mininet.cli
import
CLI
from
mininet.log
import
setLogLevel
,
info
from
mininet.link
import
Intf
,
Link
from
mininet.util
import
irange
class
NullIntf
(
Intf
):
"A dummy interface with a blank name that doesn't do any configuration"
def
__init__
(
self
,
name
,
**
params
):
self
.
name
=
''
class
NullLink
(
Link
):
"A dummy link that doesn't touch either interface"
def
makeIntfPair
(
cls
,
intf1
,
intf2
,
addr1
=
None
,
addr2
=
None
):
pass
def
delete
(
self
):
pass
class
OpticalTopo
(
Topo
):
def
build
(
self
,
n
=
3
,
tapStart
=
3
):
def
addIntf
(
self
,
switch
,
intfName
):
"Add intf intfName to switch"
self
.
addLink
(
switch
,
switch
,
cls
=
NullLink
,
intfName1
=
intfName
,
cls2
=
NullIntf
,
intfName2
=
intfName
)
def
build
(
self
,
n
=
2
,
tapStart
=
3
):
# Add hosts and switches
hosts
=
[]
switches
=
[]
for
i
in
irange
(
1
,
n
):
h
=
self
.
addHost
(
'h
%
d'
%
i
)
s
=
self
.
addSwitch
(
's
%
d'
%
i
)
s
=
self
.
addSwitch
(
's
%
d'
%
i
,
dpid
=
"0000ffffffff
%04
d"
%
i
)
self
.
addLink
(
h
,
s
)
hosts
.
append
(
h
)
switches
.
append
(
s
)
...
...
@@ -25,23 +44,23 @@ class OpticalTopo( Topo ):
# Add optical tap interfaces
tapNum
=
tapStart
for
sw
in
switches
:
self
.
add
Link
(
sw
,
sw
,
intfName1
=
'
%
s-eth0'
%
sw
,
intfName2
=
'tap
%
d'
%
tapNum
)
self
.
add
Intf
(
sw
,
'tap
%
d'
%
tapNum
)
tapNum
+=
1
# if you use, sudo mn --custom custom/optical.py, then register the topo:
#sudo mn --custom optical
-topo
.py --topo optical,5
#sudo mn --custom optical.py --topo optical,5
topos
=
{
'optical'
:
OpticalTopo
}
def
installStaticFlows
(
net
):
for
swName
in
[
's1'
,
's2'
,
's3'
,
's4'
,
's5'
,
's6'
]:
info
(
'Adding flows to
%
s...'
%
swName
)
sw
=
net
[
swName
]
for
sw
in
net
.
switches
:
info
(
'Adding flows to
%
s...'
%
sw
.
name
)
sw
.
dpctl
(
'add-flow'
,
'in_port=1,actions=output=2'
)
sw
.
dpctl
(
'add-flow'
,
'in_port=2,actions=output=1'
)
info
(
sw
.
dpctl
(
'dump-flows'
)
)
def
run
():
net
=
Mininet
(
topo
=
OpticalTopo
()
)
def
run
(
n
):
topo
=
OpticalTopo
(
n
)
net
=
Mininet
(
topo
=
topo
,
controller
=
RemoteController
,
autoSetMacs
=
True
)
net
.
start
()
#installStaticFlows( net )
CLI
(
net
)
...
...
@@ -49,5 +68,12 @@ def run():
# if the script is run directly (sudo custom/optical.py):
if
__name__
==
'__main__'
:
import
sys
try
:
n
=
int
(
sys
.
argv
[
1
]
)
except
:
print
(
'Usage: ./optical.py n # n is number of switches
\n
'
'Starting with default of 2 switches...
\n
'
)
n
=
2
setLogLevel
(
'info'
)
run
()
run
(
n
)
...
...
Please
register
or
login
to post a comment