Skip to content

Commit

Permalink
fixed issue for python3
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Xiao <xiaoquwl@gmail.com>
  • Loading branch information
xiaopeng163 committed Dec 29, 2015
1 parent 3a081b3 commit 18bc0ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions yabgp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
help='The remote BGP peer AS number'),
cfg.IntOpt('local_as',
help='The Local BGP AS number'),
cfg.StrOpt('remote_addr',
help='The remote address of the peer'),
cfg.StrOpt('local_addr',
default='0.0.0.0',
help='The local address of the BGP'),
cfg.IPOpt('remote_addr',
help='The remote address of the peer'),
cfg.IPOpt('local_addr',
default='0.0.0.0',
help='The local address of the BGP'),
cfg.StrOpt('md5',
help='The MD5 string use to auth',
secret=True),
Expand Down
4 changes: 2 additions & 2 deletions yabgp/message/attribute/mpreachnlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse(cls, value):
else:
nlri = repr(nlri_bin)

return dict(afi_safi=(afi, safi), nexthop=nexthop_bin, nlri=nlri)
return dict(afi_safi=(afi, safi), nexthop=nexthop_bin, nlri=nlri_bin)

@classmethod
def construct(cls, value):
Expand All @@ -143,7 +143,7 @@ def construct(cls, value):
nlri = IPv4FlowSpec.construct(value=value['nlri'])
if nlri:
attr_value = struct.pack('!H', afi) + struct.pack('!B', safi) + \
struct.pack('!B', len(nexthop)) + nexthop + '\x00' + nlri
struct.pack('!B', len(nexthop)) + nexthop + b'\x00' + nlri
return struct.pack('!B', cls.FLAG) + struct.pack('!B', cls.ID) \
+ struct.pack('!B', len(attr_value)) + attr_value
except Exception as e:
Expand Down
11 changes: 8 additions & 3 deletions yabgp/message/attribute/nlri/ipv6_unicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ def parse(nlri_data):
"""
nlri_list = []
while nlri_data:
prefix_bit_len = struct.unpack('!B', nlri_data[0])[0]
if isinstance(nlri_data[0], int):
prefix_bit_len = int(nlri_data[0])
else:
prefix_bit_len = struct.unpack('!B', nlri_data[0])[0]
print (type(nlri_data))
if prefix_bit_len % 8 == 0:
prefix_byte_len = prefix_bit_len / 8
else:
prefix_byte_len = prefix_bit_len / 8 + 1
prefix_addr = netaddr.IPAddress(int(binascii.b2a_hex(nlri_data[1:prefix_byte_len + 1]), 16)).__str__() \
offset = int(prefix_byte_len + 1)
prefix_addr = str(netaddr.IPAddress(int(binascii.b2a_hex(nlri_data[1:offset]), 16))) \
+ '/%s' % prefix_bit_len
nlri_list.append(prefix_addr)
nlri_data = nlri_data[prefix_byte_len + 1:]
nlri_data = nlri_data[int(prefix_byte_len) + 1:]

return nlri_list

Expand Down

0 comments on commit 18bc0ff

Please sign in to comment.