Skip to content

Commit

Permalink
Merge 4db6e9d into 203e7f0
Browse files Browse the repository at this point in the history
  • Loading branch information
zlpqingmei committed Jan 9, 2020
2 parents 203e7f0 + 4db6e9d commit 4f794c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
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
except OSError:
LOG.error('Error when reading bgp message files')
except Exception as e:
Expand Down

0 comments on commit 4f794c8

Please sign in to comment.