+static struct vsctl_port *
+add_port_to_cache(struct vsctl_context *ctx, struct vsctl_bridge *parent,
+ struct ovsrec_port *port_cfg)
+{
+ struct vsctl_port *port;
+
+ if (port_cfg->tag
+ && *port_cfg->tag >= 0 && *port_cfg->tag <= 4095) {
+ struct vsctl_bridge *vlan_bridge;
+
+ vlan_bridge = find_vlan_bridge(parent, *port_cfg->tag);
+ if (vlan_bridge) {
+ parent = vlan_bridge;
+ }
+ }
+
+ port = xmalloc(sizeof *port);
+ list_push_back(&parent->ports, &port->ports_node);
+ list_init(&port->ifaces);
+ port->port_cfg = port_cfg;
+ port->bridge = parent;
+ shash_add(&ctx->ports, port_cfg->name, port);
+
+ return port;
+}
+
+static void
+del_cached_port(struct vsctl_context *ctx, struct vsctl_port *port)
+{
+ ovs_assert(list_is_empty(&port->ifaces));
+ list_remove(&port->ports_node);
+ shash_find_and_delete(&ctx->ports, port->port_cfg->name);
+ ovsrec_port_delete(port->port_cfg);
+ free(port);
+}
+
+static struct vsctl_iface *
+add_iface_to_cache(struct vsctl_context *ctx, struct vsctl_port *parent,
+ struct ovsrec_interface *iface_cfg)
+{
+ struct vsctl_iface *iface;
+
+ iface = xmalloc(sizeof *iface);
+ list_push_back(&parent->ifaces, &iface->ifaces_node);
+ iface->iface_cfg = iface_cfg;
+ iface->port = parent;
+ shash_add(&ctx->ifaces, iface_cfg->name, iface);
+
+ return iface;
+}
+
+static void
+del_cached_iface(struct vsctl_context *ctx, struct vsctl_iface *iface)
+{
+ list_remove(&iface->ifaces_node);
+ shash_find_and_delete(&ctx->ifaces, iface->iface_cfg->name);
+ ovsrec_interface_delete(iface->iface_cfg);
+ free(iface);
+}
+