Skip to content

Commit

Permalink
feat(neighbor): support announce all processes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet2mir committed Sep 27, 2023
1 parent f3580c5 commit 4e54fd4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions etc/exabgp/api-announce-all.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api-announce-all.conf
25 changes: 25 additions & 0 deletions etc/exabgp/api-announce-all.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
process add-remove {
run ./run/api-announce.run;
encoder json;
}

process add-remove-2 {
run ./run/api-announce-2.run;
encoder json;
}

neighbor 127.0.0.1 {
router-id 1.2.3.4;
local-address 127.0.0.1;
local-as 1;
peer-as 1;
group-updates false;

capability {
graceful-restart;
}

api {
processes [ all ];
}
}
26 changes: 26 additions & 0 deletions etc/exabgp/run/api-announce-2.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import os
import sys
import time

messages = [
'announce route 1.3.0.0/24 next-hop 101.1.101.1',
'announce route 1.4.0.0/25 next-hop 101.1.101.1',
]

while messages:
message = messages.pop(0)
sys.stdout.write(message + '\n')
sys.stdout.flush()
time.sleep(0.1)

try:
now = time.time()
while os.getppid() != 1 and time.time() < now + 5:
line = sys.stdin.readline().strip()
if not line or 'shutdown' in line:
break
time.sleep(1)
except IOError:
pass
4 changes: 4 additions & 0 deletions qa/encoding/api-announce-all.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1:announce:1.1.0.0/24
1:announce:1.2.0.0/25
1:announce:1.3.0.0/25
1:announce:1.4.0.0/25
2 changes: 2 additions & 0 deletions src/exabgp/bgp/neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

# The definition of a neighbor (from reading the configuration)
class Neighbor(dict):
PROCESS_ALL = "all"

class Capability(dict):
defaults = {
'asn4': True,
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def validate(self):
for neighbor in self.neighbors.values():
for notification in neighbor.api:
for api in neighbor.api[notification]:
if not self.processes[api].get('run', ''):
if neighbor.api[notification] != [neighbor.PROCESS_ALL] and not self.processes[api].get('run', ''):
return self.error.set(
"\n\nan api called '%s' is used by neighbor '%s' but not defined\n\n"
% (api, neighbor['peer-address']),
Expand Down
4 changes: 4 additions & 0 deletions src/exabgp/reactor/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def peers(self, service=''):
if service in peer.neighbor.api['processes']:
matching.append(peer_name)
continue
if peer.neighbor.api['processes'] == [peer.neighbor.PROCESS_ALL]:
matching.append(peer_name)
continue

return matching

def handle_connection(self, peer_name, connection):
Expand Down

0 comments on commit 4e54fd4

Please sign in to comment.