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
9de7873b
Commit
9de7873b
authored
14 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Change to automatically update IP and MAC addresses.
parent
b7097daa
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
+41
-11
41 additions, 11 deletions
mininet/node.py
with
41 additions
and
11 deletions
mininet/node.py
+
41
−
11
View file @
9de7873b
...
...
@@ -48,7 +48,7 @@
from
subprocess
import
Popen
,
PIPE
,
STDOUT
from
time
import
sleep
from
mininet.log
import
info
,
error
,
warn
,
debug
from
mininet.log
import
info
,
error
,
debug
from
mininet.util
import
quietRun
,
makeIntfPair
,
moveIntf
,
isShellBuiltin
from
mininet.moduledeps
import
moduleDeps
,
OVS_KMOD
,
OF_KMOD
,
TUN
...
...
@@ -62,7 +62,7 @@ class Node( object ):
outToNode
=
{}
# mapping of output fds to nodes
portBase
=
0
# Nodes always start with eth0/port0, even in OF 1.0
def
__init__
(
self
,
name
,
inNamespace
=
True
,
defaultMAC
=
None
,
defaultIP
=
None
,
**
kwargs
):
"""
name: name of node
...
...
@@ -93,6 +93,7 @@ def __init__( self, name, inNamespace=True,
self
.
ports
=
{}
# dict of interface names to port numbers
# replace with Port objects, eventually ?
self
.
ips
=
{}
# dict of interfaces to ip addresses as strings
self
.
macs
=
{}
# dict of interfacesto mac addresses as strings
self
.
connection
=
{}
# remote node connected to each interface
self
.
execed
=
False
self
.
lastCmd
=
None
...
...
@@ -367,21 +368,50 @@ def setDefaultRoute( self, intf ):
self
.
cmd
(
'
ip route flush root 0/0
'
)
return
self
.
cmd
(
'
route add default
'
+
intf
)
def
defaultIntf
(
self
):
"
Return interface for lowest port
"
ports
=
self
.
intfs
.
keys
()
if
ports
:
return
self
.
intfs
[
min
(
ports
)
]
_ipMatchRegex
=
re
.
compile
(
r
'
\d+\.\d+\.\d+\.\d+
'
)
_macMatchRegex
=
re
.
compile
(
r
'
..:..:..:..:..:..
'
)
def
IP
(
self
,
intf
=
None
):
"
Return IP address of a node or specific interface.
"
if
len
(
self
.
ips
)
==
1
:
return
self
.
ips
.
values
()[
0
]
if
intf
:
return
self
.
ips
.
get
(
intf
,
None
)
if
intf
is
None
:
intf
=
self
.
defaultIntf
()
if
intf
and
not
self
.
waiting
:
self
.
updateIP
(
intf
)
return
self
.
ips
.
get
(
intf
,
None
)
def
MAC
(
self
,
intf
=
None
):
"
Return MAC address of a node or specific interface.
"
if
intf
is
None
and
len
(
self
.
intfs
)
==
1
:
intf
=
self
.
intfs
.
values
()[
0
]
if
intf
is
None
:
intf
=
self
.
defaultIntf
()
if
intf
and
not
self
.
waiting
:
self
.
updateMAC
(
intf
)
return
self
.
macs
.
get
(
intf
,
None
)
def
updateIP
(
self
,
intf
):
"
Update IP address for an interface
"
assert
not
self
.
waiting
ifconfig
=
self
.
cmd
(
'
ifconfig
'
+
intf
)
macs
=
re
.
findall
(
'
..:..:..:..:..:..
'
,
ifconfig
)
if
len
(
macs
)
>
0
:
return
macs
[
0
]
ips
=
self
.
_ipMatchRegex
.
findall
(
ifconfig
)
if
ips
:
self
.
ips
[
intf
]
=
ips
[
0
]
else
:
self
.
ips
[
intf
]
=
None
def
updateMAC
(
self
,
intf
):
"
Update MAC address for an interface
"
assert
not
self
.
waiting
ifconfig
=
self
.
cmd
(
'
ifconfig
'
+
intf
)
macs
=
self
.
_macMatchRegex
.
findall
(
ifconfig
)
if
macs
:
self
.
macs
[
intf
]
=
macs
[
0
]
else
:
self
.
macs
[
intf
]
=
None
def
intfIsUp
(
self
,
intf
):
"
Check if an interface is up.
"
...
...
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