+ ovsdb_idl_txn_add_comment(txn, "ovs-brcompatd: addbr %s", br_name);
+
+ iface = ovsrec_interface_insert(txn_from_openvswitch(ovs));
+ ovsrec_interface_set_name(iface, br_name);
+
+ port = ovsrec_port_insert(txn_from_openvswitch(ovs));
+ ovsrec_port_set_name(port, br_name);
+ ovsrec_port_set_interfaces(port, &iface, 1);
+
+ br = ovsrec_bridge_insert(txn_from_openvswitch(ovs));
+ ovsrec_bridge_set_name(br, br_name);
+ ovsrec_bridge_set_ports(br, &port, 1);
+
+ ovs_insert_bridge(ovs, br);
+
+ return commit_txn(txn, true);
+}
+
+static void
+add_port(const struct ovsrec_open_vswitch *ovs,
+ const struct ovsrec_bridge *br, const char *port_name)
+{
+ struct ovsrec_interface *iface;
+ struct ovsrec_port *port;
+ struct ovsrec_port **ports;
+ size_t i;
+
+ /* xxx Check conflicts? */
+ iface = ovsrec_interface_insert(txn_from_openvswitch(ovs));
+ ovsrec_interface_set_name(iface, port_name);
+
+ port = ovsrec_port_insert(txn_from_openvswitch(ovs));
+ ovsrec_port_set_name(port, port_name);
+ ovsrec_port_set_interfaces(port, &iface, 1);
+
+ ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
+ for (i = 0; i < br->n_ports; i++) {
+ ports[i] = br->ports[i];
+ }
+ ports[br->n_ports] = port;
+ ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
+ free(ports);
+}
+
+/* Deletes 'port' from 'br'.
+ *
+ * After calling this function, 'port' must not be referenced again. */
+static void
+del_port(const struct ovsrec_bridge *br, const struct ovsrec_port *port)
+{
+ struct ovsrec_port **ports;
+ size_t i, n;
+
+ /* Remove 'port' from the bridge's list of ports. */
+ ports = xmalloc(sizeof *br->ports * br->n_ports);
+ for (i = n = 0; i < br->n_ports; i++) {
+ if (br->ports[i] != port) {
+ ports[n++] = br->ports[i];
+ }
+ }
+ ovsrec_bridge_set_ports(br, ports, n);
+ free(ports);