1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Internal representation of port_no id is int(32bit)
17 # string representation is in hex without '0x'
20 _PORT_NO_FMT = '%0{0}x'.format(_PORT_NO_LEN)
21 PORT_NO_PATTERN = r'[0-9a-f]{%d}' % _PORT_NO_LEN
24 def port_no_to_str(port_no):
25 return _PORT_NO_FMT % port_no
28 def str_to_port_no(port_no_str):
29 assert len(port_no_str) == _PORT_NO_LEN
30 return int(port_no_str, 16)