#include "compiler.h"
#include "daemon.h"
#include "dirs.h"
+#include "dynamic-string.h"
#include "openvswitch/vconn.h"
#include "openvswitch/vlog.h"
#include "ovn/lib/ovn-sb-idl.h"
VLOG_DEFINE_THIS_MODULE(main);
static unixctl_cb_func ovn_controller_exit;
+static unixctl_cb_func ct_zone_list;
#define DEFAULT_BRIDGE_NAME "br-int"
static char *ovs_remote;
+const struct sbrec_chassis *
+get_chassis(struct ovsdb_idl *ovnsb_idl, const char *chassis_id)
+{
+ const struct sbrec_chassis *chassis_rec;
+
+ SBREC_CHASSIS_FOR_EACH(chassis_rec, ovnsb_idl) {
+ if (!strcmp(chassis_rec->name, chassis_id)) {
+ break;
+ }
+ }
+
+ return chassis_rec;
+}
+
+uint32_t
+get_tunnel_type(const char *name)
+{
+ if (!strcmp(name, "geneve")) {
+ return GENEVE;
+ } else if (!strcmp(name, "stt")) {
+ return STT;
+ } else if (!strcmp(name, "vxlan")) {
+ return VXLAN;
+ }
+
+ return 0;
+}
+
static const struct ovsrec_bridge *
get_bridge(struct ovsdb_idl *ovs_idl, const char *br_name)
{
bridge = ovsrec_bridge_insert(ctx->ovs_idl_txn);
ovsrec_bridge_set_name(bridge, bridge_name);
ovsrec_bridge_set_fail_mode(bridge, "secure");
- struct smap other_config = SMAP_INITIALIZER(&other_config);
- smap_add(&other_config, "disable-in-band", "true");
- ovsrec_bridge_set_other_config(bridge, &other_config);
- smap_destroy(&other_config);
+ const struct smap oc = SMAP_CONST1(&oc, "disable-in-band", "true");
+ ovsrec_bridge_set_other_config(bridge, &oc);
ovsrec_bridge_set_ports(bridge, &port, 1);
struct ovsrec_bridge **bridges;
iface = ovsrec_interface_insert(ctx->ovs_idl_txn);
ovsrec_interface_set_name(iface, port_name);
ovsrec_interface_set_type(iface, "patch");
- struct smap options = SMAP_INITIALIZER(&options);
- smap_add(&options, "peer", peer_port_name);
+ const struct smap options = SMAP_CONST1(&options, "peer", peer_port_name);
ovsrec_interface_set_options(iface, &options);
- smap_destroy(&options);
struct ovsrec_port *port;
port = ovsrec_port_insert(ctx->ovs_idl_txn);
ovsrec_port_set_name(port, port_name);
ovsrec_port_set_interfaces(port, &iface, 1);
- struct smap ext_ids = SMAP_INITIALIZER(&ext_ids);
- smap_add(&ext_ids, "ovn-patch-port", network);
- ovsrec_port_set_external_ids(port, &ext_ids);
- smap_destroy(&ext_ids);
+ const struct smap ids = SMAP_CONST1(&ids, "ovn-patch-port", network);
+ ovsrec_port_set_external_ids(port, &ids);
struct ovsrec_port **ports;
ports = xmalloc(sizeof *ports * (b1->n_ports + 1));
parse_options(argc, argv);
fatal_ignore_sigpipe();
- daemonize_start();
+ daemonize_start(false);
retval = unixctl_server_create(NULL, &unixctl);
if (retval) {
ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
+ /* Initialize connection tracking zones. */
+ struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
+ unsigned long ct_zone_bitmap[BITMAP_N_LONGS(MAX_CT_ZONES)];
+ bitmap_set1(ct_zone_bitmap, 0); /* Zone 0 is reserved. */
+ unixctl_command_register("ct-zone-list", "", 0, 0,
+ ct_zone_list, &ct_zones);
+
/* Main loop. */
exiting = false;
while (!exiting) {
if (chassis_id) {
chassis_run(&ctx, chassis_id);
encaps_run(&ctx, br_int, chassis_id);
- binding_run(&ctx, br_int, chassis_id);
+ binding_run(&ctx, br_int, chassis_id, &ct_zones, ct_zone_bitmap);
}
if (br_int) {
enum mf_field_id mff_ovn_geneve = ofctrl_run(br_int);
struct hmap flow_table = HMAP_INITIALIZER(&flow_table);
- lflow_run(&ctx, &flow_table);
+ lflow_run(&ctx, &flow_table, &ct_zones);
if (chassis_id) {
physical_run(&ctx, mff_ovn_geneve,
- br_int, chassis_id, &flow_table);
+ br_int, chassis_id, &ct_zones, &flow_table);
}
ofctrl_put(&flow_table);
hmap_destroy(&flow_table);
lflow_destroy();
ofctrl_destroy();
+ simap_destroy(&ct_zones);
+
ovsdb_idl_loop_destroy(&ovs_idl_loop);
ovsdb_idl_loop_destroy(&ovnsb_idl_loop);
unixctl_command_reply(conn, NULL);
}
+
+static void
+ct_zone_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[] OVS_UNUSED, void *ct_zones_)
+{
+ struct simap *ct_zones = ct_zones_;
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ struct simap_node *zone;
+
+ SIMAP_FOR_EACH(zone, ct_zones) {
+ ds_put_format(&ds, "%s %d\n", zone->name, zone->data);
+ }
+
+ unixctl_command_reply(conn, ds_cstr(&ds));
+ ds_destroy(&ds);
+}