Repository: faucetsdn/beka

Issue:
Comparing Bekas
It'd be great to be able to compare Bekas, using (for example):

        self.local_address = local_address
        self.bgp_port = bgp_port
        self.local_as = local_as
        self.router_id = router_id

That way we can decide whether we need to start a new Beka or not by comparing it to an existing one.

Discussion:

Patch:
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


Test patch:
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))
+