+ if self.grace != 8:
+ b = list(bin(self.grace)[2:])
+ b = b + [0] * (3 - len(b))
+ length = "\x08"
+ if b[1] == '1':
+ restart_flag = "\x80\x05"
+ else:
+ restart_flag = "\x00\x05"
+ if b[2] == '1':
+ ipv4_flag = "\x80"
+ else:
+ ipv4_flag = "\x00"
+ if b[0] == '1':
+ ll_gr = "\x47\x07\x00\x01\x01\x00\x00\x00\x1e"
+ length = "\x11"
+ else:
+ ll_gr = ""
+ logger.debug("Grace parameters list: {}".format(b))
+ # "\x02" Param type ("Capability Ad")
+ # :param length: Length of whole message
+ # "\x40" Graceful-restart capability
+ # "\x06" Length (6 bytes)
+ # "\x00" Restart Flag (customizable - turned on when grace == 2,3,6,7)
+ # "\x05" Restart timer (5sec)
+ # "\x00\x01" AFI (IPV4)
+ # "\x01" SAFI (Unicast)
+ # "\x00" Ipv4 Flag (customizable - turned on when grace == 1,3,5,7)
+ # "\x47\x07\x00\x01\x01\x00\x00\x00\x1e" ipv4 ll-graceful-restart capability, timer 30sec
+ # ll-gr turned on when grace is between 4-7
+ optional_parameter_hex = "\x02{}\x40\x06{}\x00\x01\x01{}{}".format(
+ length, restart_flag, ipv4_flag, ll_gr)
+ optional_parameters_hex += optional_parameter_hex
+