Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mininet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olaf Bergmann
mininet
Commits
0b5609f5
Commit
0b5609f5
authored
11 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Check (and canonicalize) dpid arguments to Switch()
This seems slightly ugly, but it has bitten many people. Closes #268
parent
ef677432
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mininet/node.py
+18
-14
18 additions, 14 deletions
mininet/node.py
with
18 additions
and
14 deletions
mininet/node.py
+
18
−
14
View file @
0b5609f5
...
...
@@ -752,28 +752,32 @@ class Switch( Node ):
dpidLen
=
16
# digits in dpid passed to switch
def
__init__
(
self
,
name
,
dpid
=
None
,
opts
=
''
,
listenPort
=
None
,
**
params
):
"""
dpid: dpid
for switch
(or None to derive from name, e.g. s1 -> 1)
"""
dpid: dpid
hex string
(or None to derive from name, e.g. s1 -> 1)
opts: additional switch options
listenPort: port to listen on for dpctl connections
"""
Node
.
__init__
(
self
,
name
,
**
params
)
self
.
dpid
=
(
(
'
0
'
*
self
.
dpidLen
+
dpid
.
translate
(
None
,
'
:
'
)
)
[
-
self
.
dpidLen
:
]
if
dpid
else
self
.
defaultDpid
()
)
self
.
dpid
=
self
.
defaultDpid
(
dpid
)
self
.
opts
=
opts
self
.
listenPort
=
listenPort
if
not
self
.
inNamespace
:
self
.
controlIntf
=
Intf
(
'
lo
'
,
self
,
port
=
0
)
def
defaultDpid
(
self
):
"
Derive dpid from switch name, s1 -> 1
"
try
:
dpid
=
int
(
re
.
findall
(
r
'
\d+
'
,
self
.
name
)[
0
]
)
dpid
=
hex
(
dpid
)[
2
:
]
dpid
=
'
0
'
*
(
self
.
dpidLen
-
len
(
dpid
)
)
+
dpid
return
dpid
except
IndexError
:
raise
Exception
(
'
Unable to derive default datapath ID -
'
'
please either specify a dpid or use a
'
'
canonical switch name such as s23.
'
)
def
defaultDpid
(
self
,
dpid
=
None
):
"
Return correctly formatted dpid from dpid or switch name (s1 -> 1)
"
if
dpid
:
# Remove any colons and make sure it's a good hex number
dpid
=
dpid
.
translate
(
None
,
'
:
'
)
assert
len
(
dpid
)
<=
self
.
dpidLen
and
int
(
dpid
,
16
)
>=
0
else
:
# Use hex of the first number in the switch name
nums
=
re
.
findall
(
r
'
\d+
'
,
self
.
name
)
if
nums
:
dpid
=
hex
(
int
(
nums
[
0
]
)
)[
2
:
]
else
:
raise
Exception
(
'
Unable to derive default datapath ID -
'
'
please either specify a dpid or use a
'
'
canonical switch name such as s23.
'
)
return
(
'
0
'
*
self
.
dpidLen
+
dpid
)[
-
self
.
dpidLen
:
]
def
defaultIntf
(
self
):
"
Return control interface
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment