1 /* Copyright (c) 2015 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
19 #include "lib/vswitch-idl.h"
20 #include "openvswitch/vlog.h"
21 #include "ovn/lib/ovn-sb-idl.h"
22 #include "ovn-controller.h"
24 VLOG_DEFINE_THIS_MODULE(chassis);
27 chassis_init(struct controller_ctx *ctx)
29 ovsdb_idl_add_table(ctx->ovs_idl, &ovsrec_table_open_vswitch);
30 ovsdb_idl_add_column(ctx->ovs_idl, &ovsrec_open_vswitch_col_external_ids);
34 chassis_run(struct controller_ctx *ctx, const char *chassis_id)
36 if (!ctx->ovnsb_idl_txn) {
40 const struct sbrec_chassis *chassis_rec;
41 const struct ovsrec_open_vswitch *cfg;
42 const char *encap_type, *encap_ip;
43 struct sbrec_encap *encap_rec;
44 static bool inited = false;
46 chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
48 /* xxx Need to support more than one encap. Also need to support
49 * xxx encap options. */
50 cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
52 VLOG_INFO("No Open_vSwitch row defined.");
56 encap_type = smap_get(&cfg->external_ids, "ovn-encap-type");
57 encap_ip = smap_get(&cfg->external_ids, "ovn-encap-ip");
58 if (!encap_type || !encap_ip) {
59 VLOG_INFO("Need to specify an encap type and ip");
66 for (i = 0; i < chassis_rec->n_encaps; i++) {
67 if (!strcmp(chassis_rec->encaps[i]->type, encap_type)
68 && !strcmp(chassis_rec->encaps[i]->ip, encap_ip)) {
69 /* Nothing changed. */
73 VLOG_WARN("Chassis config changing on startup, make sure "
74 "multiple chassis are not configured : %s/%s->%s/%s",
75 chassis_rec->encaps[i]->type,
76 chassis_rec->encaps[i]->ip,
77 encap_type, encap_ip);
83 ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
84 "ovn-controller: registering chassis '%s'",
88 chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
89 sbrec_chassis_set_name(chassis_rec, chassis_id);
92 encap_rec = sbrec_encap_insert(ctx->ovnsb_idl_txn);
94 sbrec_encap_set_type(encap_rec, encap_type);
95 sbrec_encap_set_ip(encap_rec, encap_ip);
97 sbrec_chassis_set_encaps(chassis_rec, &encap_rec, 1);
102 /* Returns true if the database is all cleaned up, false if more work is
105 chassis_cleanup(struct controller_ctx *ctx, const char *chassis_id)
107 /* Delete Chassis row. */
108 const struct sbrec_chassis *chassis_rec
109 = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
113 if (ctx->ovnsb_idl_txn) {
114 ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
115 "ovn-controller: unregistering chassis '%s'",
117 sbrec_chassis_delete(chassis_rec);