ovsdb/query.h \
ovsdb/row.c \
ovsdb/row.h \
+ ovsdb/server.c \
+ ovsdb/server.h \
ovsdb/table.c \
ovsdb/table.h \
ovsdb/trigger.c \
#include "ovsdb.h"
#include "reconnect.h"
#include "row.h"
+#include "server.h"
#include "stream.h"
#include "table.h"
#include "timeval.h"
/* JSON-RPC database server. */
struct ovsdb_jsonrpc_server {
- struct ovsdb *db;
+ struct ovsdb_server up;
unsigned int n_sessions, max_sessions;
struct shash remotes; /* Contains "struct ovsdb_jsonrpc_remote *"s. */
};
ovsdb_jsonrpc_server_create(struct ovsdb *db)
{
struct ovsdb_jsonrpc_server *server = xzalloc(sizeof *server);
- server->db = db;
+ ovsdb_server_init(&server->up, db);
server->max_sessions = 64;
shash_init(&server->remotes);
return server;
ovsdb_jsonrpc_server_del_remote(node);
}
shash_destroy(&svr->remotes);
+ ovsdb_server_destroy(&svr->up);
free(svr);
}
/* JSON-RPC database server session. */
struct ovsdb_jsonrpc_session {
+ struct ovsdb_session up;
struct ovsdb_jsonrpc_remote *remote;
struct list node; /* Element in remote's sessions list. */
/* Triggers. */
struct hmap triggers; /* Hmap of "struct ovsdb_jsonrpc_trigger"s. */
- struct list completions; /* Completed triggers. */
/* Monitors. */
struct hmap monitors; /* Hmap of "struct ovsdb_jsonrpc_monitor"s. */
struct ovsdb_jsonrpc_session *s;
s = xzalloc(sizeof *s);
+ ovsdb_session_init(&s->up, remote->server->up.db);
s->remote = remote;
list_push_back(&remote->sessions, &s->node);
hmap_init(&s->triggers);
hmap_init(&s->monitors);
- list_init(&s->completions);
s->js = js;
s->js_seqno = jsonrpc_session_get_seqno(js);
jsonrpc_session_close(s->js);
list_remove(&s->node);
s->remote->server->n_sessions--;
+ ovsdb_session_destroy(&s->up);
free(s);
}
static const char *
get_db_name(const struct ovsdb_jsonrpc_session *s)
{
- return s->remote->server->db->schema->name;
+ return s->remote->server->up.db->schema->name;
}
static struct jsonrpc_msg *
reply = ovsdb_jsonrpc_check_db_name(s, request);
if (!reply) {
reply = jsonrpc_create_reply(
- ovsdb_schema_to_json(s->remote->server->db->schema),
+ ovsdb_schema_to_json(s->remote->server->up.db->schema),
request->id);
}
} else if (!strcmp(request->method, "list_dbs")) {
struct ovsdb_jsonrpc_trigger {
struct ovsdb_trigger trigger;
- struct ovsdb_jsonrpc_session *session;
struct hmap_node hmap_node; /* In session's "triggers" hmap. */
struct json *id;
};
/* Insert into trigger table. */
t = xmalloc(sizeof *t);
- ovsdb_trigger_init(s->remote->server->db,
- &t->trigger, params, &s->completions,
- time_msec());
- t->session = s;
+ ovsdb_trigger_init(&s->up, &t->trigger, params, time_msec());
t->id = id;
hmap_insert(&s->triggers, &t->hmap_node, hash);
static void
ovsdb_jsonrpc_trigger_complete(struct ovsdb_jsonrpc_trigger *t)
{
- struct ovsdb_jsonrpc_session *s = t->session;
+ struct ovsdb_jsonrpc_session *s;
+
+ s = CONTAINER_OF(t->trigger.session, struct ovsdb_jsonrpc_session, up);
if (jsonrpc_session_is_connected(s->js)) {
struct jsonrpc_msg *reply;
static void
ovsdb_jsonrpc_trigger_complete_done(struct ovsdb_jsonrpc_session *s)
{
- while (!list_is_empty(&s->completions)) {
+ while (!list_is_empty(&s->up.completions)) {
struct ovsdb_jsonrpc_trigger *t
- = CONTAINER_OF(s->completions.next,
+ = CONTAINER_OF(s->up.completions.next,
struct ovsdb_jsonrpc_trigger, trigger.node);
ovsdb_jsonrpc_trigger_complete(t);
}
m = xzalloc(sizeof *m);
ovsdb_replica_init(&m->replica, &ovsdb_jsonrpc_replica_class);
- ovsdb_add_replica(s->remote->server->db, &m->replica);
+ ovsdb_add_replica(s->remote->server->up.db, &m->replica);
m->session = s;
hmap_insert(&s->monitors, &m->node, json_hash(monitor_id, 0));
m->monitor_id = json_clone(monitor_id);
const struct json *mr_value;
size_t i;
- table = ovsdb_get_table(s->remote->server->db, node->name);
+ table = ovsdb_get_table(s->remote->server->up.db, node->name);
if (!table) {
error = ovsdb_syntax_error(NULL, NULL,
"no table named %s", node->name);
error:
if (m) {
- ovsdb_remove_replica(s->remote->server->db, &m->replica);
+ ovsdb_remove_replica(s->remote->server->up.db, &m->replica);
}
json = ovsdb_error_to_json(error);
return jsonrpc_create_error(json_string_create("unknown monitor"),
request_id);
} else {
- ovsdb_remove_replica(s->remote->server->db, &m->replica);
+ ovsdb_remove_replica(s->remote->server->up.db, &m->replica);
return jsonrpc_create_reply(json_object_create(), request_id);
}
}
struct ovsdb_jsonrpc_monitor *m, *next;
HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) {
- ovsdb_remove_replica(s->remote->server->db, &m->replica);
+ ovsdb_remove_replica(s->remote->server->up.db, &m->replica);
}
}
--- /dev/null
+/* Copyright (c) 2011 Nicira Networks
+ *
+ * Licensed 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 <config.h>
+
+#include "server.h"
+
+/* Initializes 'session' as a session that operates on 'db'. */
+void
+ovsdb_session_init(struct ovsdb_session *session, struct ovsdb *db)
+{
+ session->db = db;
+ list_init(&session->completions);
+}
+
+/* Destroys 'session'. */
+void
+ovsdb_session_destroy(struct ovsdb_session *session OVS_UNUSED)
+{
+}
+
+/* Initializes 'server' as a server that operates on 'db'. */
+void
+ovsdb_server_init(struct ovsdb_server *server, struct ovsdb *db)
+{
+ server->db = db;
+}
+
+/* Destroys 'server'. */
+void
+ovsdb_server_destroy(struct ovsdb_server *server OVS_UNUSED)
+{
+}
--- /dev/null
+/* Copyright (c) 2011 Nicira Networks
+ *
+ * Licensed 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.
+ */
+
+#ifndef SERVER_H
+#define SERVER_H 1
+
+#include "hmap.h"
+#include "list.h"
+
+/* Abstract representation of an OVSDB client connection, not tied to any
+ * particular network protocol. Protocol implementations
+ * (e.g. jsonrpc-server.c) embed this in a larger data structure. */
+struct ovsdb_session {
+ struct ovsdb *db;
+ struct list completions; /* Completed triggers. */
+};
+
+void ovsdb_session_init(struct ovsdb_session *, struct ovsdb *);
+void ovsdb_session_destroy(struct ovsdb_session *);
+
+/* Abstract representation of an OVSDB server not tied to any particular
+ * network protocol. Protocol implementations (e.g. jsonrpc-server.c) embed
+ * this in a larger data structure. */
+struct ovsdb_server {
+ struct ovsdb *db;
+};
+
+void ovsdb_server_init(struct ovsdb_server *, struct ovsdb *);
+void ovsdb_server_destroy(struct ovsdb_server *);
+
+#endif /* ovsdb/server.h */
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "jsonrpc.h"
#include "ovsdb.h"
#include "poll-loop.h"
+#include "server.h"
-static bool ovsdb_trigger_try(struct ovsdb *db, struct ovsdb_trigger *,
- long long int now);
+static bool ovsdb_trigger_try(struct ovsdb_trigger *, long long int now);
static void ovsdb_trigger_complete(struct ovsdb_trigger *);
void
-ovsdb_trigger_init(struct ovsdb *db, struct ovsdb_trigger *trigger,
- struct json *request, struct list *completion,
- long long int now)
+ovsdb_trigger_init(struct ovsdb_session *session,
+ struct ovsdb_trigger *trigger,
+ struct json *request, long long int now)
{
- list_push_back(&db->triggers, &trigger->node);
- trigger->completion = completion;
+ trigger->session = session;
+ list_push_back(&trigger->session->db->triggers, &trigger->node);
trigger->request = request;
trigger->result = NULL;
trigger->created = now;
trigger->timeout_msec = LLONG_MAX;
- ovsdb_trigger_try(db, trigger, now);
+ ovsdb_trigger_try(trigger, now);
}
void
db->run_triggers = false;
LIST_FOR_EACH_SAFE (t, next, node, &db->triggers) {
if (run_triggers || now - t->created >= t->timeout_msec) {
- ovsdb_trigger_try(db, t, now);
+ ovsdb_trigger_try(t, now);
}
}
}
}
static bool
-ovsdb_trigger_try(struct ovsdb *db, struct ovsdb_trigger *t, long long int now)
+ovsdb_trigger_try(struct ovsdb_trigger *t, long long int now)
{
- t->result = ovsdb_execute(db, t->request, now - t->created,
- &t->timeout_msec);
+ t->result = ovsdb_execute(t->session->db, t->request,
+ now - t->created, &t->timeout_msec);
if (t->result) {
ovsdb_trigger_complete(t);
return true;
{
assert(t->result != NULL);
list_remove(&t->node);
- list_push_back(t->completion, &t->node);
+ list_push_back(&t->session->completions, &t->node);
}
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct ovsdb;
struct ovsdb_trigger {
- struct list node; /* !result: in struct ovsdb "triggers" list;
- * result: in completion list. */
- struct list *completion; /* Completion list. */
+ struct ovsdb_session *session; /* Session that owns this trigger. */
+ struct list node; /* !result: in session->db->triggers;
+ * result: in session->completions. */
struct json *request; /* Database request. */
struct json *result; /* Result (null if none yet). */
long long int created; /* Time created. */
long long int timeout_msec; /* Max wait duration. */
};
-void ovsdb_trigger_init(struct ovsdb *, struct ovsdb_trigger *,
- struct json *request, struct list *completion,
- long long int now);
+void ovsdb_trigger_init(struct ovsdb_session *, struct ovsdb_trigger *,
+ struct json *request, long long int now);
void ovsdb_trigger_destroy(struct ovsdb_trigger *);
bool ovsdb_trigger_is_complete(const struct ovsdb_trigger *);
#include "ovsdb/ovsdb.h"
#include "ovsdb/query.h"
#include "ovsdb/row.h"
+#include "ovsdb/server.h"
#include "ovsdb/table.h"
#include "ovsdb/transaction.h"
#include "ovsdb/trigger.h"
do_trigger(int argc OVS_UNUSED, char *argv[])
{
struct ovsdb_schema *schema;
- struct list completions;
+ struct ovsdb_session session;
struct json *json;
struct ovsdb *db;
long long int now;
json_destroy(json);
db = ovsdb_create(schema);
- list_init(&completions);
+ ovsdb_session_init(&session, db);
+
now = 0;
number = 0;
for (i = 2; i < argc; i++) {
json_destroy(params);
} else {
struct test_trigger *t = xmalloc(sizeof *t);
- ovsdb_trigger_init(db, &t->trigger, params, &completions, now);
+ ovsdb_trigger_init(&session, &t->trigger, params, now);
t->number = number++;
if (ovsdb_trigger_is_complete(&t->trigger)) {
do_trigger_dump(t, now, "immediate");
}
ovsdb_trigger_run(db, now);
- while (!list_is_empty(&completions)) {
- do_trigger_dump(CONTAINER_OF(list_pop_front(&completions),
+ while (!list_is_empty(&session.completions)) {
+ do_trigger_dump(CONTAINER_OF(list_pop_front(&session.completions),
struct test_trigger, trigger.node),
now, "delayed");
}