Skip to content

Commit

Permalink
enhance sr-policy support compatiblity of old and new version of iox (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
meidli authored and xiaopeng163 committed Nov 24, 2017
1 parent b49f9b4 commit 6e2ee65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ build-stamp
ChangeLog
covhtml/
doc/build
*.DS_Store
*.DS_Store
.vscode/settings.json
2 changes: 2 additions & 0 deletions yabgp/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
# Sub-TLVs as defined in SR TE Policy draft
BGPSUB_TLV_PREFERENCE = 6
BGPSUB_TLV_BINDGINGSID = 7
BGPSUB_TLV_PREFERENCE_NEW = 12
BGPSUB_TLV_BINDGINGSID_NEW = 13
BGPSUB_TLV_SIDLIST = 128

# Sub-TLVs as defined in SR TE Policy draft and used in BGPSUB_TLV_SIDLIST
Expand Down
37 changes: 29 additions & 8 deletions yabgp/message/attribute/tunnelencaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,44 @@ def construct(cls, value):
data = dict([(int(l), r) for (l, r) in policy.items()])
policy_value_hex = b''
items = data.keys()
# Binding SID Sub-TLV
if bgp_cons.BGPSUB_TLV_BINDGINGSID not in items:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID) + struct.pack('!B', 2) +\
b'\x00\x00'
if bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW not in items:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW) + struct.pack('!B', 2) +\
b'\x00\x00'
if bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW in items:
if data[bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW] is None:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW) + struct.pack('!B', 2) +\
b'\x00\x00'
else:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW) + struct.pack('!B', 6) +\
b'\x00\x00' + struct.pack('!I', data[bgp_cons.BGPSUB_TLV_BINDGINGSID_NEW] << 12)
else:
# format of binding sid is same with the mpls label
# the high order 20 bit was truly used as the bsid
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Label | ... |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID) + struct.pack('!B', 6) +\
b'\x00\x00' + struct.pack('!I', data[bgp_cons.BGPSUB_TLV_BINDGINGSID] << 12)
if data[bgp_cons.BGPSUB_TLV_BINDGINGSID] is None:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID) + struct.pack('!B', 2) +\
b'\x00\x00'
else:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_BINDGINGSID) + struct.pack('!B', 6) +\
b'\x00\x00' + struct.pack('!I', data[bgp_cons.BGPSUB_TLV_BINDGINGSID] << 12)
# Preference Sub-TLV
if bgp_cons.BGPSUB_TLV_PREFERENCE not in items:
if bgp_cons.BGPSUB_TLV_PREFERENCE_NEW in items:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_PREFERENCE_NEW) + struct.pack('!B', 6) + \
b'\x00\x00' + struct.pack('!I', data[bgp_cons.BGPSUB_TLV_PREFERENCE_NEW])
else:
policy_value_hex += struct.pack('!B', bgp_cons.BGPSUB_TLV_PREFERENCE) + struct.pack('!B', 6) + \
b'\x00\x00' + struct.pack('!I', data[bgp_cons.BGPSUB_TLV_PREFERENCE])
for type_tmp in items:
if type_tmp == bgp_cons.BGPSUB_TLV_PREFERENCE:
# if type_tmp == bgp_cons.BGPSUB_TLV_PREFERENCE:
# Sub_TLV preference
policy_value_hex += struct.pack('!B', type_tmp) + struct.pack('!B', 6) + \
b'\x00\x00' + struct.pack('!I', data[type_tmp])
elif type_tmp == bgp_cons.BGPSUB_TLV_SIDLIST:
# policy_value_hex += struct.pack('!B', type_tmp) + struct.pack('!B', 6) + \
# b'\x00\x00' + struct.pack('!I', data[type_tmp])
if type_tmp == bgp_cons.BGPSUB_TLV_SIDLIST:
# Sub_TLV segment list
seg_list_hex = b''
for seg_list in data[type_tmp]:
Expand Down

0 comments on commit 6e2ee65

Please sign in to comment.