summaryrefslogtreecommitdiff
path: root/qpid/extras/dispatch/src
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2013-10-02 15:04:33 +0000
committerTed Ross <tross@apache.org>2013-10-02 15:04:33 +0000
commit2377e55440363c4cca55fff4777051165cc023fa (patch)
treed92203f9d884b565b96b46a63a357f5f5c2a5d5c /qpid/extras/dispatch/src
parent636f2f7a339a2576f935cd013edd27cd1fe86aa6 (diff)
downloadqpid-python-2377e55440363c4cca55fff4777051165cc023fa.tar.gz
QPID-5045 - Added additional indexing for inter-router links.
QPID-5201 - Fixed compile issues under "Release" builds. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1528512 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/extras/dispatch/src')
-rw-r--r--qpid/extras/dispatch/src/python_embedded.c5
-rw-r--r--qpid/extras/dispatch/src/router_node.c257
-rw-r--r--qpid/extras/dispatch/src/router_private.h41
-rw-r--r--qpid/extras/dispatch/src/router_pynode.c253
4 files changed, 301 insertions, 255 deletions
diff --git a/qpid/extras/dispatch/src/python_embedded.c b/qpid/extras/dispatch/src/python_embedded.c
index 97ece06c86..a3c41f86f5 100644
--- a/qpid/extras/dispatch/src/python_embedded.c
+++ b/qpid/extras/dispatch/src/python_embedded.c
@@ -614,9 +614,6 @@ static void dx_register_log_constant(PyObject *module, const char *name, uint32_
static void dx_python_setup()
{
- PyObject *laType = (PyObject*) &LogAdapterType;
- PyObject *ioaType = (PyObject*) &IoAdapterType;
-
LogAdapterType.tp_new = PyType_GenericNew;
IoAdapterType.tp_new = PyType_GenericNew;
if ((PyType_Ready(&LogAdapterType) < 0) || (PyType_Ready(&IoAdapterType) < 0)) {
@@ -629,6 +626,7 @@ static void dx_python_setup()
//
// Add LogAdapter
//
+ PyTypeObject *laType = &LogAdapterType;
Py_INCREF(laType);
PyModule_AddObject(m, "LogAdapter", (PyObject*) &LogAdapterType);
@@ -641,6 +639,7 @@ static void dx_python_setup()
dx_register_log_constant(m, "LOG_CRITICAL", LOG_CRITICAL);
//
+ PyTypeObject *ioaType = &IoAdapterType;
Py_INCREF(ioaType);
PyModule_AddObject(m, "IoAdapter", (PyObject*) &IoAdapterType);
diff --git a/qpid/extras/dispatch/src/router_node.c b/qpid/extras/dispatch/src/router_node.c
index 240f6cdc41..fea3695620 100644
--- a/qpid/extras/dispatch/src/router_node.c
+++ b/qpid/extras/dispatch/src/router_node.c
@@ -28,9 +28,6 @@
static char *module = "ROUTER";
-static void dx_router_python_setup(dx_router_t *router);
-static void dx_pyrouter_tick(dx_router_t *router);
-
static char *local_prefix = "_local/";
static char *topo_prefix = "_topo/";
@@ -116,7 +113,7 @@ static void dx_router_generate_temp_addr(dx_router_t *router, char *buffer, size
long int rnd = random();
int idx;
- for (idx = 0; idx < 10; idx++)
+ for (idx = 0; idx < 6; idx++)
discriminator[idx] = table[(rnd >> (idx * 6)) & 63];
discriminator[idx] = '\0';
@@ -640,6 +637,7 @@ static int router_outgoing_link_handler(void* context, dx_link_t *link)
//
dx_router_add_link_ref_LH(&router->router_addr->rlinks, rlink);
rlink->owning_addr = router->router_addr;
+ router->out_links_by_mask_bit[rlink->mask_bit] = rlink;
} else {
//
@@ -648,7 +646,7 @@ static int router_outgoing_link_handler(void* context, dx_link_t *link)
// address, that address needs to be set up in the address list.
//
dx_field_iterator_t *iter;
- char temp_addr[1000];
+ char temp_addr[1000]; // FIXME
dx_address_t *addr;
if (is_dynamic) {
@@ -714,6 +712,17 @@ static int router_link_detach_handler(void* context, dx_link_t *link, int closed
}
//
+ // If this is an outgoing inter-router link, we must remove the by-mask-bit
+ // index reference to this link.
+ //
+ if (rlink->link_type == DX_LINK_ROUTER && rlink->link_direction == DX_OUTGOING) {
+ if (router->out_links_by_mask_bit[rlink->mask_bit] == rlink)
+ router->out_links_by_mask_bit[rlink->mask_bit] = 0;
+ else
+ dx_log(module, LOG_CRITICAL, "Outgoing router link closing but not in index: bit=%d", rlink->mask_bit);
+ }
+
+ //
// If this is an incoming inter-router link, we must free the mask_bit.
//
if (rlink->link_type == DX_LINK_ROUTER && rlink->link_direction == DX_INCOMING)
@@ -809,6 +818,12 @@ static void router_outbound_open_handler(void *type_context, dx_connection_t *co
//
dx_router_add_link_ref_LH(&router->router_addr->rlinks, rlink);
+ //
+ // Index this link from the by-maskbit index so we can later find it quickly
+ // when provided with the mask bit.
+ //
+ router->out_links_by_mask_bit[mask_bit] = rlink;
+
dx_link_set_context(sender, rlink);
DEQ_INSERT_TAIL(router->links, rlink);
sys_mutex_unlock(router->lock);
@@ -867,6 +882,10 @@ dx_router_t *dx_router(dx_dispatch_t *dx, const char *area, const char *id)
DEQ_INIT(router->links);
DEQ_INIT(router->routers);
+ router->out_links_by_mask_bit = NEW_PTR_ARRAY(dx_router_link_t, dx_bitmask_width());
+ for (int idx = 0; idx < dx_bitmask_width(); idx++)
+ router->out_links_by_mask_bit[idx] = 0;
+
router->neighbor_free_mask = dx_bitmask(1);
router->lock = sys_mutex();
router->timer = dx_timer(dx, dx_router_timer_handler, (void*) router);
@@ -1031,231 +1050,3 @@ void dx_router_send2(dx_dispatch_t *dx,
dx_field_iterator_free(iter);
}
-
-//===============================================================================
-// Python Router Adapter
-//===============================================================================
-
-typedef struct {
- PyObject_HEAD
- dx_router_t *router;
-} RouterAdapter;
-
-
-static PyObject* dx_router_node_updated(PyObject *self, PyObject *args)
-{
- //RouterAdapter *adapter = (RouterAdapter*) self;
- //dx_router_t *router = adapter->router;
- const char *address;
- int is_reachable;
- int is_neighbor;
- int link_maskbit;
- int router_maskbit;
-
- if (!PyArg_ParseTuple(args, "siiii", &address, &is_reachable, &is_neighbor,
- &link_maskbit, &router_maskbit))
- return 0;
-
- // TODO
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject* dx_router_add_route(PyObject *self, PyObject *args)
-{
- //RouterAdapter *adapter = (RouterAdapter*) self;
- const char *addr;
- const char *peer;
-
- if (!PyArg_ParseTuple(args, "ss", &addr, &peer))
- return 0;
-
- // TODO
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyObject* dx_router_del_route(PyObject *self, PyObject *args)
-{
- //RouterAdapter *adapter = (RouterAdapter*) self;
- const char *addr;
- const char *peer;
-
- if (!PyArg_ParseTuple(args, "ss", &addr, &peer))
- return 0;
-
- // TODO
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-static PyMethodDef RouterAdapter_methods[] = {
- {"node_updated", dx_router_node_updated, METH_VARARGS, "Update the status of a remote router node"},
- {"add_route", dx_router_add_route, METH_VARARGS, "Add a newly discovered route"},
- {"del_route", dx_router_del_route, METH_VARARGS, "Delete a route"},
- {0, 0, 0, 0}
-};
-
-static PyTypeObject RouterAdapterType = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size*/
- "dispatch.RouterAdapter", /* tp_name*/
- sizeof(RouterAdapter), /* tp_basicsize*/
- 0, /* tp_itemsize*/
- 0, /* tp_dealloc*/
- 0, /* tp_print*/
- 0, /* tp_getattr*/
- 0, /* tp_setattr*/
- 0, /* tp_compare*/
- 0, /* tp_repr*/
- 0, /* tp_as_number*/
- 0, /* tp_as_sequence*/
- 0, /* tp_as_mapping*/
- 0, /* tp_hash */
- 0, /* tp_call*/
- 0, /* tp_str*/
- 0, /* tp_getattro*/
- 0, /* tp_setattro*/
- 0, /* tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /* tp_flags*/
- "Dispatch Router Adapter", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- RouterAdapter_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0, /* tp_weaklist */
- 0, /* tp_del */
- 0 /* tp_version_tag */
-};
-
-
-static void dx_router_python_setup(dx_router_t *router)
-{
- PyObject *raType = (PyObject*) &RouterAdapterType;
- PyObject *pDispatchModule = dx_python_module();
-
- RouterAdapterType.tp_new = PyType_GenericNew;
- if (PyType_Ready(&RouterAdapterType) < 0) {
- PyErr_Print();
- dx_log(module, LOG_CRITICAL, "Unable to initialize the Python Router Adapter");
- return;
- }
-
- Py_INCREF(raType);
- PyModule_AddObject(pDispatchModule, "RouterAdapter", (PyObject*) &RouterAdapterType);
-
- //
- // Attempt to import the Python Router module
- //
- PyObject* pName;
- PyObject* pId;
- PyObject* pArea;
- PyObject* pMaxRouters;
- PyObject* pModule;
- PyObject* pClass;
- PyObject* pArgs;
-
- pName = PyString_FromString("qpid.dispatch.router");
- pModule = PyImport_Import(pName);
- Py_DECREF(pName);
- if (!pModule) {
- dx_log(module, LOG_CRITICAL, "Can't Locate 'router' Python module");
- return;
- }
-
- pClass = PyObject_GetAttrString(pModule, "RouterEngine");
- if (!pClass || !PyClass_Check(pClass)) {
- dx_log(module, LOG_CRITICAL, "Can't Locate 'RouterEngine' class in the 'router' module");
- return;
- }
-
- PyObject *adapterType = PyObject_GetAttrString(pDispatchModule, "RouterAdapter");
- PyObject *adapterInstance = PyObject_CallObject(adapterType, 0);
- assert(adapterInstance);
-
- ((RouterAdapter*) adapterInstance)->router = router;
-
- //
- // Constructor Arguments for RouterEngine
- //
- pArgs = PyTuple_New(4);
-
- // arg 0: adapter instance
- PyTuple_SetItem(pArgs, 0, adapterInstance);
-
- // arg 1: router_id
- pId = PyString_FromString(router->router_id);
- PyTuple_SetItem(pArgs, 1, pId);
-
- // arg 2: area_id
- pArea = PyString_FromString(router->router_area);
- PyTuple_SetItem(pArgs, 2, pArea);
-
- // arg 3: max_routers
- pMaxRouters = PyInt_FromLong((long) dx_bitmask_width());
- PyTuple_SetItem(pArgs, 3, pMaxRouters);
-
- //
- // Instantiate the router
- //
- router->pyRouter = PyInstance_New(pClass, pArgs, 0);
- Py_DECREF(pArgs);
- Py_DECREF(adapterType);
-
- if (!router->pyRouter) {
- PyErr_Print();
- dx_log(module, LOG_CRITICAL, "'RouterEngine' class cannot be instantiated");
- return;
- }
-
- router->pyTick = PyObject_GetAttrString(router->pyRouter, "handleTimerTick");
- if (!router->pyTick || !PyCallable_Check(router->pyTick)) {
- dx_log(module, LOG_CRITICAL, "'RouterEngine' class has no handleTimerTick method");
- return;
- }
-}
-
-
-static void dx_pyrouter_tick(dx_router_t *router)
-{
- PyObject *pArgs;
- PyObject *pValue;
-
- if (router->pyTick) {
- pArgs = PyTuple_New(0);
- pValue = PyObject_CallObject(router->pyTick, pArgs);
- if (PyErr_Occurred()) {
- PyErr_Print();
- }
- Py_DECREF(pArgs);
- if (pValue) {
- Py_DECREF(pValue);
- }
- }
-}
-
diff --git a/qpid/extras/dispatch/src/router_private.h b/qpid/extras/dispatch/src/router_private.h
index 23c8b74a62..7f1f7486fb 100644
--- a/qpid/extras/dispatch/src/router_private.h
+++ b/qpid/extras/dispatch/src/router_private.h
@@ -25,6 +25,8 @@ typedef struct dx_router_ref_t dx_router_ref_t;
typedef struct dx_router_link_ref_t dx_router_link_ref_t;
typedef struct dx_router_conn_t dx_router_conn_t;
+void dx_router_python_setup(dx_router_t *router);
+void dx_pyrouter_tick(dx_router_t *router);
typedef enum {
DX_LINK_ENDPOINT, // A link to a connected endpoint
@@ -112,25 +114,26 @@ DEQ_DECLARE(dx_address_t, dx_address_list_t);
struct dx_router_t {
- dx_dispatch_t *dx;
- const char *router_area;
- const char *router_id;
- dx_node_t *node;
-
- dx_address_list_t addrs;
- hash_t *addr_hash;
- dx_address_t *router_addr;
-
- dx_router_link_list_t links;
- dx_router_node_list_t routers;
-
- dx_bitmask_t *neighbor_free_mask;
- sys_mutex_t *lock;
- dx_timer_t *timer;
- uint64_t dtag;
-
- PyObject *pyRouter;
- PyObject *pyTick;
+ dx_dispatch_t *dx;
+ const char *router_area;
+ const char *router_id;
+ dx_node_t *node;
+
+ dx_address_list_t addrs;
+ hash_t *addr_hash;
+ dx_address_t *router_addr;
+
+ dx_router_link_list_t links;
+ dx_router_node_list_t routers;
+ dx_router_link_t **out_links_by_mask_bit;
+
+ dx_bitmask_t *neighbor_free_mask;
+ sys_mutex_t *lock;
+ dx_timer_t *timer;
+ uint64_t dtag;
+
+ PyObject *pyRouter;
+ PyObject *pyTick;
};
#endif
diff --git a/qpid/extras/dispatch/src/router_pynode.c b/qpid/extras/dispatch/src/router_pynode.c
new file mode 100644
index 0000000000..9930c5dde9
--- /dev/null
+++ b/qpid/extras/dispatch/src/router_pynode.c
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <qpid/dispatch/python_embedded.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <qpid/dispatch.h>
+#include "dispatch_private.h"
+#include "router_private.h"
+
+static char *module = "router.pynode";
+
+typedef struct {
+ PyObject_HEAD
+ dx_router_t *router;
+} RouterAdapter;
+
+
+static PyObject* dx_router_node_updated(PyObject *self, PyObject *args)
+{
+ //RouterAdapter *adapter = (RouterAdapter*) self;
+ //dx_router_t *router = adapter->router;
+ const char *address;
+ int is_reachable;
+ int is_neighbor;
+ int link_maskbit;
+ int router_maskbit;
+
+ if (!PyArg_ParseTuple(args, "siiii", &address, &is_reachable, &is_neighbor,
+ &link_maskbit, &router_maskbit))
+ return 0;
+
+ // TODO
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject* dx_router_add_route(PyObject *self, PyObject *args)
+{
+ //RouterAdapter *adapter = (RouterAdapter*) self;
+ const char *addr;
+ const char *peer;
+
+ if (!PyArg_ParseTuple(args, "ss", &addr, &peer))
+ return 0;
+
+ // TODO
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyObject* dx_router_del_route(PyObject *self, PyObject *args)
+{
+ //RouterAdapter *adapter = (RouterAdapter*) self;
+ const char *addr;
+ const char *peer;
+
+ if (!PyArg_ParseTuple(args, "ss", &addr, &peer))
+ return 0;
+
+ // TODO
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+static PyMethodDef RouterAdapter_methods[] = {
+ {"node_updated", dx_router_node_updated, METH_VARARGS, "Update the status of a remote router node"},
+ {"add_route", dx_router_add_route, METH_VARARGS, "Add a newly discovered route"},
+ {"del_route", dx_router_del_route, METH_VARARGS, "Delete a route"},
+ {0, 0, 0, 0}
+};
+
+static PyTypeObject RouterAdapterType = {
+ PyObject_HEAD_INIT(0)
+ 0, /* ob_size*/
+ "dispatch.RouterAdapter", /* tp_name*/
+ sizeof(RouterAdapter), /* tp_basicsize*/
+ 0, /* tp_itemsize*/
+ 0, /* tp_dealloc*/
+ 0, /* tp_print*/
+ 0, /* tp_getattr*/
+ 0, /* tp_setattr*/
+ 0, /* tp_compare*/
+ 0, /* tp_repr*/
+ 0, /* tp_as_number*/
+ 0, /* tp_as_sequence*/
+ 0, /* tp_as_mapping*/
+ 0, /* tp_hash */
+ 0, /* tp_call*/
+ 0, /* tp_str*/
+ 0, /* tp_getattro*/
+ 0, /* tp_setattro*/
+ 0, /* tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT, /* tp_flags*/
+ "Dispatch Router Adapter", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ RouterAdapter_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+ 0, /* tp_del */
+ 0 /* tp_version_tag */
+};
+
+
+void dx_router_python_setup(dx_router_t *router)
+{
+ PyObject *pDispatchModule = dx_python_module();
+
+ RouterAdapterType.tp_new = PyType_GenericNew;
+ if (PyType_Ready(&RouterAdapterType) < 0) {
+ PyErr_Print();
+ dx_log(module, LOG_CRITICAL, "Unable to initialize the Python Router Adapter");
+ return;
+ }
+
+ PyTypeObject *raType = &RouterAdapterType;
+ Py_INCREF(raType);
+ PyModule_AddObject(pDispatchModule, "RouterAdapter", (PyObject*) &RouterAdapterType);
+
+ //
+ // Attempt to import the Python Router module
+ //
+ PyObject* pName;
+ PyObject* pId;
+ PyObject* pArea;
+ PyObject* pMaxRouters;
+ PyObject* pModule;
+ PyObject* pClass;
+ PyObject* pArgs;
+
+ pName = PyString_FromString("qpid.dispatch.router");
+ pModule = PyImport_Import(pName);
+ Py_DECREF(pName);
+ if (!pModule) {
+ dx_log(module, LOG_CRITICAL, "Can't Locate 'router' Python module");
+ return;
+ }
+
+ pClass = PyObject_GetAttrString(pModule, "RouterEngine");
+ if (!pClass || !PyClass_Check(pClass)) {
+ dx_log(module, LOG_CRITICAL, "Can't Locate 'RouterEngine' class in the 'router' module");
+ return;
+ }
+
+ PyObject *adapterType = PyObject_GetAttrString(pDispatchModule, "RouterAdapter");
+ PyObject *adapterInstance = PyObject_CallObject(adapterType, 0);
+ assert(adapterInstance);
+
+ ((RouterAdapter*) adapterInstance)->router = router;
+
+ //
+ // Constructor Arguments for RouterEngine
+ //
+ pArgs = PyTuple_New(4);
+
+ // arg 0: adapter instance
+ PyTuple_SetItem(pArgs, 0, adapterInstance);
+
+ // arg 1: router_id
+ pId = PyString_FromString(router->router_id);
+ PyTuple_SetItem(pArgs, 1, pId);
+
+ // arg 2: area_id
+ pArea = PyString_FromString(router->router_area);
+ PyTuple_SetItem(pArgs, 2, pArea);
+
+ // arg 3: max_routers
+ pMaxRouters = PyInt_FromLong((long) dx_bitmask_width());
+ PyTuple_SetItem(pArgs, 3, pMaxRouters);
+
+ //
+ // Instantiate the router
+ //
+ router->pyRouter = PyInstance_New(pClass, pArgs, 0);
+ Py_DECREF(pArgs);
+ Py_DECREF(adapterType);
+
+ if (!router->pyRouter) {
+ PyErr_Print();
+ dx_log(module, LOG_CRITICAL, "'RouterEngine' class cannot be instantiated");
+ return;
+ }
+
+ router->pyTick = PyObject_GetAttrString(router->pyRouter, "handleTimerTick");
+ if (!router->pyTick || !PyCallable_Check(router->pyTick)) {
+ dx_log(module, LOG_CRITICAL, "'RouterEngine' class has no handleTimerTick method");
+ return;
+ }
+}
+
+
+void dx_pyrouter_tick(dx_router_t *router)
+{
+ PyObject *pArgs;
+ PyObject *pValue;
+
+ if (router->pyTick) {
+ pArgs = PyTuple_New(0);
+ pValue = PyObject_CallObject(router->pyTick, pArgs);
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ Py_DECREF(pArgs);
+ if (pValue) {
+ Py_DECREF(pValue);
+ }
+ }
+}
+