Revision 54037995 mininet/util.py

View differences:

mininet/util.py
177 177
    setrlimit( RLIMIT_NPROC, (4096, 8192))
178 178
    setrlimit( RLIMIT_NOFILE, (16384, 32768))
179 179

  
180

  
181
def _colonHex(val, bytes):
182
    '''Generate colon-hex string.
183

  
184
    @param val input as unsigned int
185
    @param bytes number of bytes to convert
186
    @return ch_str colon-hex string
187
    '''
188
    pieces = []
189
    for i in range (bytes - 1, -1, -1):
190
        pieces.append('%02x' % (((0xff << (i * 8)) & val) >> (i * 8)))
191
    ch_str = ':'.join(pieces)
192
    return ch_str
193

  
194

  
180 195
def macColonHex(mac):
181 196
    '''Generate MAC colon-hex string from unsigned int.
182 197

  
183 198
    @param mac MAC address as unsigned int
184 199
    @return mac_str MAC colon-hex string
185 200
    '''
186
    mac_pieces = []
187
    for i in range (5, -1, -1):
188
        mac_pieces.append('%02x' % (((0xff << (i * 8)) & mac) >> (i * 8)))
189
    mac_str = ':'.join(mac_pieces)
190
    return mac_str
201
    return _colonHex(mac, 6)
202

  
191 203

  
192 204
def ipStr(ip):
193 205
    '''Generate IP address string

Also available in: Unified diff