Revision d44a5843 mininet/util.py

View differences:

mininet/util.py
101 101
       printError: if true, print error"""
102 102
    retry( retries, delaySecs, moveIntfNoRetry, intf, node, printError )
103 103

  
104
def createLink( node1, port1, node2, port2 ):
104
def createLink( node1, node2, port1=None, port2=None ):
105 105
    """Create a link between nodes, making an interface for each.
106 106
       node1: Node object
107
       port1: node1 port number
108 107
       node2: Node object
109
       port2: node2 port number
108
       port1: node1 port number (optional)
109
       port2: node2 port number (optional)
110 110
       returns: intf1 name, intf2 name"""
111
    intf1 = node1.intfName( port1 )
112
    intf2 = node2.intfName( port2 )
113
    makeIntfPair( intf1, intf2 )
114
    node1.addIntf( intf1, port1 )
115
    node2.addIntf( intf2, port2 )
116
    node1.connect( intf1, node2, intf2 )
117
    node2.connect( intf2, node1, intf1 )
118
    return intf1, intf2
111
    return node1.linkTo( node2, port1, port2 )
119 112

  
120 113
def fixLimits():
121 114
    "Fix ridiculously small resource limits."
......
141 134
    return _colonHex( mac, 6 )
142 135

  
143 136
def ipStr( ip ):
144
    """Generate IP address string from an unsigned int
145
       ip: unsigned int of form x << 16 | y << 8 | z
146
       returns: ip address string 10.x.y.z """
147
    hi = ( ip & 0xff0000 ) >> 16
148
    mid = ( ip & 0xff00 ) >> 8
149
    lo = ip & 0xff
150
    return "10.%i.%i.%i" % ( hi, mid, lo )
137
    """Generate IP address string from an unsigned int.
138
       ip: unsigned int of form w << 24 | x << 16 | y << 8 | z
139
       returns: ip address string w.x.y.z, or 10.x.y.z if w==0"""
140
    w = ( ip & 0xff000000 ) >> 24
141
    w = 10 if w == 0 else w
142
    x = ( ip & 0xff0000 ) >> 16
143
    y = ( ip & 0xff00 ) >> 8
144
    z = ip & 0xff
145
    return "%i.%i.%i.%i" % ( w, x, y, z )
146

  
147
def ipNum( w, x, y, z ):
148
    """Generate unsigned int from components ofIP address
149
       returns: w << 24 | x << 16 | y << 8 | z"""
150
    return  ( w << 24 ) | ( x << 16 ) | ( y << 8 ) | z
151

  
152
def ipParse( ip ):
153
    "Parse an IP address and return an unsigned int."
154
    args = [ int( arg ) for arg in ip.split( '.' ) ]
155
    return ipNum( *args )

Also available in: Unified diff