]>
Commit | Line | Data |
---|---|---|
717c7fc5 JP |
1 | /* Copyright (c) 2015 Nicira, Inc. |
2 | * | |
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: | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
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. | |
14 | */ | |
15 | ||
16 | #include <config.h> | |
17 | #include "chassis.h" | |
18 | ||
717c7fc5 JP |
19 | #include "lib/vswitch-idl.h" |
20 | #include "openvswitch/vlog.h" | |
e3df8838 | 21 | #include "ovn/lib/ovn-sb-idl.h" |
717c7fc5 JP |
22 | #include "ovn-controller.h" |
23 | ||
24 | VLOG_DEFINE_THIS_MODULE(chassis); | |
25 | ||
26 | void | |
4a5a9e06 | 27 | chassis_register_ovs_idl(struct ovsdb_idl *ovs_idl) |
717c7fc5 | 28 | { |
4a5a9e06 BP |
29 | ovsdb_idl_add_table(ovs_idl, &ovsrec_table_open_vswitch); |
30 | ovsdb_idl_add_column(ovs_idl, &ovsrec_open_vswitch_col_external_ids); | |
717c7fc5 JP |
31 | } |
32 | ||
deab5e67 | 33 | void |
4acc496e | 34 | chassis_run(struct controller_ctx *ctx, const char *chassis_id) |
717c7fc5 | 35 | { |
deab5e67 BP |
36 | if (!ctx->ovnsb_idl_txn) { |
37 | return; | |
38 | } | |
39 | ||
717c7fc5 JP |
40 | const struct sbrec_chassis *chassis_rec; |
41 | const struct ovsrec_open_vswitch *cfg; | |
42 | const char *encap_type, *encap_ip; | |
e4901fe0 | 43 | struct sbrec_encap *encap_rec; |
717c7fc5 JP |
44 | static bool inited = false; |
45 | ||
4acc496e | 46 | chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, chassis_id); |
717c7fc5 JP |
47 | |
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); | |
51 | if (!cfg) { | |
52 | VLOG_INFO("No Open_vSwitch row defined."); | |
53 | return; | |
54 | } | |
55 | ||
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"); | |
60 | return; | |
61 | } | |
62 | ||
63 | if (chassis_rec) { | |
64 | int i; | |
65 | ||
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. */ | |
70 | inited = true; | |
71 | return; | |
72 | } else if (!inited) { | |
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); | |
78 | } | |
79 | ||
80 | } | |
81 | } | |
82 | ||
f1fd7657 | 83 | ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn, |
e4901fe0 | 84 | "ovn-controller: registering chassis '%s'", |
4acc496e | 85 | chassis_id); |
e4901fe0 JP |
86 | |
87 | if (!chassis_rec) { | |
f1fd7657 | 88 | chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn); |
4acc496e | 89 | sbrec_chassis_set_name(chassis_rec, chassis_id); |
e4901fe0 JP |
90 | } |
91 | ||
f1fd7657 | 92 | encap_rec = sbrec_encap_insert(ctx->ovnsb_idl_txn); |
e4901fe0 JP |
93 | |
94 | sbrec_encap_set_type(encap_rec, encap_type); | |
95 | sbrec_encap_set_ip(encap_rec, encap_ip); | |
96 | ||
97 | sbrec_chassis_set_encaps(chassis_rec, &encap_rec, 1); | |
98 | ||
717c7fc5 JP |
99 | inited = true; |
100 | } | |
101 | ||
f1fd7657 BP |
102 | /* Returns true if the database is all cleaned up, false if more work is |
103 | * required. */ | |
104 | bool | |
4acc496e | 105 | chassis_cleanup(struct controller_ctx *ctx, const char *chassis_id) |
717c7fc5 | 106 | { |
30a4256f BP |
107 | if (!chassis_id) { |
108 | return true; | |
109 | } | |
110 | ||
f1fd7657 BP |
111 | /* Delete Chassis row. */ |
112 | const struct sbrec_chassis *chassis_rec | |
4acc496e | 113 | = get_chassis_by_name(ctx->ovnsb_idl, chassis_id); |
deab5e67 BP |
114 | if (!chassis_rec) { |
115 | return true; | |
116 | } | |
117 | if (ctx->ovnsb_idl_txn) { | |
f1fd7657 | 118 | ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn, |
717c7fc5 | 119 | "ovn-controller: unregistering chassis '%s'", |
4acc496e | 120 | chassis_id); |
717c7fc5 | 121 | sbrec_chassis_delete(chassis_rec); |
e4901fe0 | 122 | } |
deab5e67 | 123 | return false; |
717c7fc5 | 124 | } |