You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2015/10/20 23:35:44 UTC

[2/2] qpid-dispatch git commit: DISPATCH-179 - Added framework for route table management.

DISPATCH-179 - Added framework for route table management.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/f03cca6b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/f03cca6b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/f03cca6b

Branch: refs/heads/tross-DISPATCH-179-1
Commit: f03cca6bbb64aa142326ab35a51716d16d696181
Parents: 3333d77
Author: Ted Ross <tr...@redhat.com>
Authored: Tue Oct 20 17:34:38 2015 -0400
Committer: Ted Ross <tr...@redhat.com>
Committed: Tue Oct 20 17:34:38 2015 -0400

----------------------------------------------------------------------
 include/qpid/dispatch/router_core.h   |   9 +-
 src/CMakeLists.txt                    |   1 +
 src/router_core/route_tables.c        | 203 +++++++++++++++++++++++++++++
 src/router_core/route_tables.h        |  22 ++++
 src/router_core/router_core.c         |  34 +++++
 src/router_core/router_core_private.h |  46 +++----
 src/router_core/router_core_thread.c  |   7 +-
 7 files changed, 281 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/include/qpid/dispatch/router_core.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/router_core.h b/include/qpid/dispatch/router_core.h
index a78da02..87bcd5c 100644
--- a/include/qpid/dispatch/router_core.h
+++ b/include/qpid/dispatch/router_core.h
@@ -52,15 +52,16 @@ void qdr_core_set_link(qdr_core_t *core, int router_maskbit, int link_maskbit);
 void qdr_core_remove_link(qdr_core_t *core, int router_maskbit);
 void qdr_core_set_next_hop(qdr_core_t *core, int router_maskbit, int nh_router_maskbit);
 void qdr_core_remove_next_hop(qdr_core_t *core, int router_maskbit);
-void qdr_core_set_valid_origins(qdr_core_t *core, const qd_bitmask_t *routers);
-void qdr_core_map_destination(qdr_core_t *core, int router_maskbit, const char *address, char phase);
-void qdr_core_unmap_destination(qdr_core_t *core, int router_maskbit, const char *address, char phase);
+void qdr_core_set_valid_origins(qdr_core_t *core, int router_maskbit, qd_bitmask_t *routers);
+void qdr_core_map_destination(qdr_core_t *core, int router_maskbit, const char *address, char aclass, char phase);
+void qdr_core_unmap_destination(qdr_core_t *core, int router_maskbit, const char *address, char aclass, char phase);
 
 typedef void (*qdr_mobile_added_t)   (void *context, const char *address);
 typedef void (*qdr_mobile_removed_t) (void *context, const char *address);
 typedef void (*qdr_link_lost_t)      (void *context, int link_maskbit);
 
-void qdr_core_route_table_handlers(void                 *context,
+void qdr_core_route_table_handlers(qdr_core_t           *core, 
+                                   void                 *context,
                                    qdr_mobile_added_t    mobile_added,
                                    qdr_mobile_removed_t  mobile_removed,
                                    qdr_link_lost_t       link_lost);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b20a1a5..a9136b1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -67,6 +67,7 @@ set(qpid_dispatch_SOURCES
   router_config.c
   router_core/router_core.c
   router_core/router_core_thread.c
+  router_core/route_tables.c
   router_delivery.c
   router_node.c
   router_forwarders.c

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/router_core/route_tables.c
----------------------------------------------------------------------
diff --git a/src/router_core/route_tables.c b/src/router_core/route_tables.c
new file mode 100644
index 0000000..bd102f0
--- /dev/null
+++ b/src/router_core/route_tables.c
@@ -0,0 +1,203 @@
+/*
+ * 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 "router_core_private.h"
+//#include "route_tables.h"
+
+static qdr_action_t *qdr_action(qdr_action_handler_t action_handler);
+static void qdr_action_enqueue(qdr_core_t *core, qdr_action_t *action);
+
+static void qdrh_add_router(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_del_router(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_set_link(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_remove_link(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_set_next_hop(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_remove_next_hop(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_set_valid_origins(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_map_destination(qdr_core_t *core, qdr_action_t *action);
+static void qdrh_unmap_destination(qdr_core_t *core, qdr_action_t *action);
+
+
+//==================================================================================
+// Interface Functions
+//==================================================================================
+
+void qdr_core_add_router(qdr_core_t *core, const char *address, int router_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_add_router);
+    action->args.route_table.router_maskbit = router_maskbit;
+    action->args.route_table.address        = qdr_field(address);
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_del_router(qdr_core_t *core, int router_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_del_router);
+    action->args.route_table.router_maskbit = router_maskbit;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_set_link(qdr_core_t *core, int router_maskbit, int link_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_set_link);
+    action->args.route_table.router_maskbit = router_maskbit;
+    action->args.route_table.link_maskbit   = link_maskbit;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_remove_link(qdr_core_t *core, int router_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_remove_link);
+    action->args.route_table.router_maskbit = router_maskbit;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_set_next_hop(qdr_core_t *core, int router_maskbit, int nh_router_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_set_next_hop);
+    action->args.route_table.router_maskbit    = router_maskbit;
+    action->args.route_table.nh_router_maskbit = nh_router_maskbit;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_remove_next_hop(qdr_core_t *core, int router_maskbit)
+{
+    qdr_action_t *action = qdr_action(qdrh_remove_next_hop);
+    action->args.route_table.router_maskbit = router_maskbit;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_set_valid_origins(qdr_core_t *core, int router_maskbit, qd_bitmask_t *routers)
+{
+    qdr_action_t *action = qdr_action(qdrh_set_valid_origins);
+    action->args.route_table.router_maskbit = router_maskbit;
+    action->args.route_table.router_set     = routers;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_map_destination(qdr_core_t *core, int router_maskbit, const char *address, char aclass, char phase)
+{
+    qdr_action_t *action = qdr_action(qdrh_map_destination);
+    action->args.route_table.router_maskbit = router_maskbit;
+    action->args.route_table.address        = qdr_field(address);
+    action->args.route_table.address_phase  = phase;
+    action->args.route_table.address_class  = aclass;
+    qdr_action_enqueue(core, action);
+}
+
+
+void qdr_core_unmap_destination(qdr_core_t *core, int router_maskbit, const char *address, char aclass, char phase)
+{
+    qdr_action_t *action = qdr_action(qdrh_unmap_destination);
+    action->args.route_table.router_maskbit = router_maskbit;
+    action->args.route_table.address        = qdr_field(address);
+    action->args.route_table.address_phase  = phase;
+    action->args.route_table.address_class  = aclass;
+    qdr_action_enqueue(core, action);
+}
+
+void qdr_core_route_table_handlers(qdr_core_t           *core, 
+                                   void                 *context,
+                                   qdr_mobile_added_t    mobile_added,
+                                   qdr_mobile_removed_t  mobile_removed,
+                                   qdr_link_lost_t       link_lost)
+{
+    core->rt_context        = context;
+    core->rt_mobile_added   = mobile_added;
+    core->rt_mobile_removed = mobile_removed;
+    core->rt_link_lost      = link_lost;
+}
+
+
+//==================================================================================
+// Internal Functions
+//==================================================================================
+
+static qdr_action_t *qdr_action(qdr_action_handler_t action_handler)
+{
+    qdr_action_t *action = new_qdr_action_t();
+    ZERO(action);
+    action->action_handler = action_handler;
+    return action;
+}
+
+static void qdr_action_enqueue(qdr_core_t *core, qdr_action_t *action)
+{
+    sys_mutex_lock(core->lock);
+    DEQ_INSERT_TAIL(core->action_list, action);
+    sys_mutex_unlock(core->lock);
+}
+
+
+//==================================================================================
+// In-Thread Functions
+//==================================================================================
+
+static void qdrh_add_router(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_del_router(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_set_link(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_remove_link(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_set_next_hop(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_remove_next_hop(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_set_valid_origins(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_map_destination(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+
+static void qdrh_unmap_destination(qdr_core_t *core, qdr_action_t *action)
+{
+}
+
+

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/router_core/route_tables.h
----------------------------------------------------------------------
diff --git a/src/router_core/route_tables.h b/src/router_core/route_tables.h
new file mode 100644
index 0000000..13980c4
--- /dev/null
+++ b/src/router_core/route_tables.h
@@ -0,0 +1,22 @@
+#ifndef __core_route_tables_h__
+#define __core_route_tables_h__ 1
+/*
+ * 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.
+ */
+
+#endif

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/router_core/router_core.c
----------------------------------------------------------------------
diff --git a/src/router_core/router_core.c b/src/router_core/router_core.c
index eba6150..7293caf 100644
--- a/src/router_core/router_core.c
+++ b/src/router_core/router_core.c
@@ -62,4 +62,38 @@ void qdr_core_free(qdr_core_t *core)
 }
 
 
+ALLOC_DECLARE(qdr_field_t);
+ALLOC_DEFINE(qdr_field_t);
+
+qdr_field_t *qdr_field(const char *text)
+{
+    size_t       length  = strlen(text);
+    size_t       ilength = length;
+    qdr_field_t *field   = new_qdr_field_t();
+    qd_buffer_t *buf;
+    ZERO(field);
+
+    while (length > 0) {
+        buf = qd_buffer();
+        size_t cap  = qd_buffer_capacity(buf);
+        size_t copy = length > cap ? cap : length;
+        memcpy(qd_buffer_cursor(buf), text, copy);
+        qd_buffer_insert(buf, copy);
+        length -= copy;
+        text   += copy;
+        DEQ_INSERT_TAIL(field->buffers, buf);
+    }
+
+    field->iterator = qd_field_iterator_buffer(DEQ_HEAD(field->buffers), 0, ilength);
+
+    return field;
+}
+
+
+void qdr_field_free(qdr_field_t *field)
+{
+    qd_field_iterator_free(field->iterator);
+    qd_buffer_list_free_buffers(&field->buffers);
+    free_qdr_field_t(field);
+}
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/router_core/router_core_private.h
----------------------------------------------------------------------
diff --git a/src/router_core/router_core_private.h b/src/router_core/router_core_private.h
index 673ae68..94ec4a1 100644
--- a/src/router_core/router_core_private.h
+++ b/src/router_core/router_core_private.h
@@ -26,40 +26,19 @@
 #include <memory.h>
 
 typedef struct {
-    qd_buffer_t         *buffer;
+    qd_buffer_list_t     buffers;
     qd_field_iterator_t *iterator;
 } qdr_field_t;
 
-typedef enum {
-    QDR_ACTION_ADD_ROUTER,
-    QDR_ACTION_DEL_ROUTER,
-    QDR_ACTION_SET_LINK,
-    QDR_ACTION_REMOVE_LINK,
-    QDR_ACTION_SET_NEXT_HOP,
-    QDR_ACTION_REMOVE_NEXT_HOP,
-    QDR_ACTION_SET_VALID_ORIGINS,
-    QDR_ACTION_MAP_DESTINATION,
-    QDR_ACTION_UNMAP_DESTINATION,
-    QDR_ACTION_SUBSCRIBE,
-    QDR_ACTION_CONNECTION_OPENED,
-    QDR_ACTION_CONNECTION_CLOSED,
-    QDR_ACTION_LINK_FIRST_ATTACH,
-    QDR_ACTION_LINK_SECOND_ATTACH,
-    QDR_ACTION_LINK_DETACH,
-    QDR_ACTION_DELIVER,
-    QDR_ACTION_DELIVER_TO,
-    QDR_ACTION_DISPOSITION_CHANGE,
-    QDR_ACTION_FLOW_CHANGE,
-    QDR_ACTION_MANAGE_CREATE,
-    QDR_ACTION_MANAGE_DELETE,
-    QDR_ACTION_MANAGE_READ,
-    QDR_ACTION_MANAGE_GET_FIRST,
-    QDR_ACTION_MANAGE_GET_NEXT
-} qdr_action_type_t;
+qdr_field_t *qdr_field(const char *string);
+void qdr_field_free(qdr_field_t *field);
 
-typedef struct qdr_action_t {
-    DEQ_LINKS(struct qdr_action_t);
-    qdr_action_type_t  action_type;
+typedef struct qdr_action_t qdr_action_t;
+typedef void (*qdr_action_handler_t) (qdr_core_t *core, qdr_action_t *action);
+
+struct qdr_action_t {
+    DEQ_LINKS(qdr_action_t);
+    qdr_action_handler_t action_handler;
     union {
         struct {
             int           link_maskbit;
@@ -71,7 +50,7 @@ typedef struct qdr_action_t {
             char          address_phase;
         } route_table;
     } args;
-} qdr_action_t;
+};
 
 ALLOC_DECLARE(qdr_action_t);
 DEQ_DECLARE(qdr_action_t, qdr_action_list_t);
@@ -83,6 +62,11 @@ struct qdr_core_t {
     sys_thread_t      *thread;
     bool               running;
     qdr_action_list_t  action_list;
+
+    void                 *rt_context;
+    qdr_mobile_added_t    rt_mobile_added;
+    qdr_mobile_removed_t  rt_mobile_removed;
+    qdr_link_lost_t       rt_link_lost;
 };
 
 void *router_core_thread(void *arg);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/f03cca6b/src/router_core/router_core_thread.c
----------------------------------------------------------------------
diff --git a/src/router_core/router_core_thread.c b/src/router_core/router_core_thread.c
index 1d08bd3..87f8c02 100644
--- a/src/router_core/router_core_thread.c
+++ b/src/router_core/router_core_thread.c
@@ -30,11 +30,6 @@
 ALLOC_DEFINE(qdr_action_t);
 
 
-static void router_core_do_action(qdr_core_t *core, qdr_action_t *action)
-{
-}
-
-
 void *router_core_thread(void *arg)
 {
     qdr_core_t      *core = (qdr_core_t*) arg;
@@ -69,7 +64,7 @@ void *router_core_thread(void *arg)
             DEQ_REMOVE_HEAD(action_list);
 
             if (core->running)
-                router_core_do_action(core, action);
+                action->action_handler(core, action);
 
             free_qdr_action_t(action);
             action = DEQ_HEAD(action_list);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org