Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/hijack.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
cfg.BoolOpt('hijack',
default=True,
help='hijack'),
cfg.IntOpt('num',default=10,
cfg.IntOpt('num', default=10,
help='new next hop address'),
]

Expand Down Expand Up @@ -167,7 +167,7 @@ def send_update():
message_count -= 1
continue

if message_count>= start_number and message_count < start_number+ 100:
if message_count >= start_number and message_count < start_number + CONF.attribute.num:

message = message_json['msg']

Expand Down
34 changes: 24 additions & 10 deletions yabgp/handler/default_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,30 @@ def get_last_seq_and_file(msg_path):
file_list.sort()
msg_file_name = file_list[-1]
try:
with open(msg_path + msg_file_name, 'r') as fh:
line = None
for line in fh:
pass
last = line
if line:
if last.startswith('['):
last_seq = eval(last)[1]
elif last.startswith('{'):
last_seq = json.loads(last)['seq']
with open(msg_path + msg_file_name, 'rb') as fh:
offset = -500
break_flag = False
while True:
fh.seek(offset, 2)
lines = fh.readlines()
if len(lines) >= 5:
for i in range(len(lines)-1, 0, -1):
last = lines[i]
try:
if last.startswith('['):
last_seq = eval(last)[1]
break_flag = True
break
elif last.startswith('{'):
last_seq = json.loads(last)['seq']
break_flag = True
break
except Exception as e:
LOG.error(e)
LOG.error(last)
if break_flag:
break
offset *= 2
Copy link
Member

@xiaopeng163 xiaopeng163 Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, you use try-except to get the last real seq(if last line is complete) or the seq before last line(if last line is incomplete) as last seq.

how about if catch an exception, and we know exactly that exception is caused by last line incomplete, we return the last seq as last seq + 1.

{seq: 2}
{se.....}  # incomplete

and we return last seq = 3, because the next line should be started from seq =4

how do you think @meidli

except OSError:
LOG.error('Error when reading bgp message files')
except Exception as e:
Expand Down