aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Russell <sam.h.russell@gmail.com>2018-10-17 17:27:51 +1300
committerSam Russell <sam.h.russell@gmail.com>2018-10-17 17:27:51 +1300
commit8a8b7cae1bdf99eb86dd7605816e7bba60636e2f (patch)
tree3b3c056dd9861d8152bc6372e37b9ca48e3532eb
parenta9e33b75342afa0a8e96d8b3475df8b6a5611af3 (diff)
downloadbeka-compare_bekas.tar.gz
beka-compare_bekas.tar.bz2
beka-compare_bekas.zip
Compare Bekas by IP and portcompare_bekas
Add Beka#listening_on method to check whether a Beka is already configured for an IP:port combination Resolves #10
-rw-r--r--beka/beka.py3
-rw-r--r--test/test_beka.py17
2 files changed, 20 insertions, 0 deletions
diff --git a/beka/beka.py b/beka/beka.py
index 8985684..2907ceb 100644
--- a/beka/beka.py
+++ b/beka/beka.py
@@ -97,3 +97,6 @@ class Beka(object):
self.stream_server.stop()
for peering in self.peerings:
peering.shutdown()
+
+ def listening_on(self, address, port):
+ return self.local_address == address and self.bgp_port == port
diff --git a/test/test_beka.py b/test/test_beka.py
index b5de955..066fd0a 100644
--- a/test/test_beka.py
+++ b/test/test_beka.py
@@ -48,3 +48,20 @@ class BekaTestCase(unittest.TestCase):
)
)
+ def test_listening_on(self):
+ beka = Beka(
+ local_address='1.2.3.4',
+ bgp_port=12345,
+ local_as=23456,
+ router_id='4.3.2.1',
+ peer_up_handler=None,
+ peer_down_handler=None,
+ route_handler=None,
+ error_handler=None
+ )
+ self.assertTrue(beka.listening_on('1.2.3.4', 12345))
+ self.assertFalse(beka.listening_on('1.2.3.4', 23456))
+ self.assertFalse(beka.listening_on('4.3.2.1', 12345))
+ self.assertFalse(beka.listening_on('4.3.2.1', 23456))
+ self.assertFalse(beka.listening_on('8.8.8.8', 53))
+