## Revision 5a8bb489 mininet/util.py

View differences:

mininet/util.py
224 224
```       returns: w << 24 | x << 16 | y << 8 | z"""
```
225 225
```    return  ( w << 24 ) | ( x << 16 ) | ( y << 8 ) | z
```
226 226

227
```def ipAdd( i, prefixLen=8, ipBaseNum=0x0a000000 ):
```
228
```    """Return IP address string from ints
```
229
```       i: int to be added to ipbase
```
230
```       prefixLen: optional IP prefix length
```
231
```       ipBaseNum: option base IP address as int
```
232
```       returns IP address as string"""
```
233
```    # Ugly but functional
```
234
```    assert i < ( 1 << ( 32 - prefixLen ) )
```
235
```    mask = 0xffffffff ^ ( ( 1 << prefixLen ) - 1 )
```
236
```    ipnum = i + ( ipBaseNum & mask )
```
237
```    return ipStr( ipnum )
```
238

227 239
```def ipParse( ip ):
```
228 240
```    "Parse an IP address and return an unsigned int."
```
229 241
```    args = [ int( arg ) for arg in ip.split( '.' ) ]
```
......
275 287
```    "To sort sanely/alphabetically: sorted( l, key=natural )"
```
276 288
```    def num( s ):
```
277 289
```        "Convert text segment to int if necessary"
```
278
```        return int( s ) if s.isdigit() else text
```
290
```        return int( s ) if s.isdigit() else s
```
279 291
```    return [  num( s ) for s in re.split( r'(\d+)', text ) ]
```
280 292

293
```def naturalSeq( t ):
```
294
```    "Natural sort key function for sequences"
```
295
```    return [ natural( x ) for x in t ]
```
296

281 297
```def numCores():
```
282 298
```    "Returns number of CPU cores based on /proc/cpuinfo"
```
283 299
```    if hasattr( numCores, 'ncores' ):
```
......
288 304
```        return 0
```
289 305
```    return numCores.ncores
```
290 306

307
```def irange(start, end):
```
308
```    """Inclusive range from start to end (vs. Python insanity.)
```
309
```       irange(1,5) -> 1, 2, 3, 4, 5"""
```
310
```    return range( start, end + 1 )
```
311

291 312
```def custom( cls, **params ):
```
292 313
```    "Returns customized constructor for class cls."
```
293 314
```    def customized( *args, **kwargs):
```

Also available in: Unified diff