diff --git a/.gitignore b/.gitignore index 5149dca..e3690a8 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,5 @@ build-stamp ChangeLog covhtml/ doc/build -*.DS_Store \ No newline at end of file +*.DS_Store +.vscode/settings.json diff --git a/yabgp/common/constants.py b/yabgp/common/constants.py index e520004..ea48c8c 100644 --- a/yabgp/common/constants.py +++ b/yabgp/common/constants.py @@ -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 diff --git a/yabgp/message/attribute/tunnelencaps.py b/yabgp/message/attribute/tunnelencaps.py index d41812a..975bbe5 100644 --- a/yabgp/message/attribute/tunnelencaps.py +++ b/yabgp/message/attribute/tunnelencaps.py @@ -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]: