[ovs-dev,ovn,2/2] Refactor physical module functions to take context argument - physical_ctx.
diff mbox series

Message ID 20200110192606.2919071-1-numans@ovn.org
State Changes Requested
Headers show
Series
  • [ovs-dev,ovn,1/2] Refactor lflow functions to take one context argument - lflow_ctx.
Related show

Commit Message

Numan Siddique Jan. 10, 2020, 7:26 p.m. UTC
From: Numan Siddique <numans@ovn.org>

No functional changes are introduced in this patch.

Signed-off-by: Numan Siddique <numans@ovn.org>
---
 controller/ovn-controller.c | 185 ++++++++++++++----------------------
 controller/physical.c       | 126 +++++++++++-------------
 controller/physical.h       |  46 ++++-----
 3 files changed, 144 insertions(+), 213 deletions(-)

Comments

Han Zhou Jan. 11, 2020, 5:38 p.m. UTC | #1
On Fri, Jan 10, 2020 at 11:26 AM <numans@ovn.org> wrote:
>
> From: Numan Siddique <numans@ovn.org>
>
> No functional changes are introduced in this patch.
>

Similar comment to what I had for the patch 1, but here since the output
parameter is only one - the desired flow table, so I think we could just
move it out from the ctx structure instead of two structures.

> Signed-off-by: Numan Siddique <numans@ovn.org>
> ---
>  controller/ovn-controller.c | 185 ++++++++++++++----------------------
>  controller/physical.c       | 126 +++++++++++-------------
>  controller/physical.h       |  46 ++++-----
>  3 files changed, 144 insertions(+), 213 deletions(-)
>
> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
> index 4942df6c4..390057ee2 100644
> --- a/controller/ovn-controller.c
> +++ b/controller/ovn-controller.c
> @@ -1213,6 +1213,68 @@ struct ed_type_flow_output {
>      struct lflow_resource_ref lflow_resource_ref;
>  };
>
> +static void init_physical_ctx(struct engine_node *node,
> +                              struct ed_type_runtime_data *rt_data,
> +                              struct ovn_desired_flow_table *flow_table,
> +                              struct physical_ctx *p_ctx)
> +{
> +    struct ovsdb_idl_index *sbrec_port_binding_by_name =
> +        engine_ovsdb_node_get_index(
> +                engine_get_input("SB_port_binding", node),
> +                "name");
> +
> +    struct sbrec_multicast_group_table *multicast_group_table =
> +        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
> +            engine_get_input("SB_multicast_group", node));
> +
> +    struct sbrec_port_binding_table *port_binding_table =
> +        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
> +            engine_get_input("SB_port_binding", node));
> +
> +    struct sbrec_chassis_table *chassis_table =
> +        (struct sbrec_chassis_table *)EN_OVSDB_GET(
> +            engine_get_input("SB_chassis", node));
> +
> +    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
> +        engine_get_input_data("mff_ovn_geneve", node);
> +
> +    struct ovsrec_open_vswitch_table *ovs_table =
> +        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
> +            engine_get_input("OVS_open_vswitch", node));
> +    struct ovsrec_bridge_table *bridge_table =
> +        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
> +            engine_get_input("OVS_bridge", node));
> +    const struct ovsrec_bridge *br_int = get_br_int(bridge_table,
ovs_table);
> +    const char *chassis_id = chassis_get_id();
> +    const struct sbrec_chassis *chassis = NULL;
> +    struct ovsdb_idl_index *sbrec_chassis_by_name =
> +        engine_ovsdb_node_get_index(
> +                engine_get_input("SB_chassis", node),
> +                "name");
> +    if (chassis_id) {
> +        chassis = chassis_lookup_by_name(sbrec_chassis_by_name,
chassis_id);
> +    }
> +
> +    ovs_assert(br_int && chassis);
> +
> +    struct ed_type_ct_zones *ct_zones_data =
> +        engine_get_input_data("ct_zones", node);
> +    struct simap *ct_zones = &ct_zones_data->current;
> +
> +    p_ctx->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
> +    p_ctx->port_binding_table = port_binding_table;
> +    p_ctx->mc_group_table = multicast_group_table;
> +    p_ctx->br_int = br_int;
> +    p_ctx->chassis_table = chassis_table;
> +    p_ctx->chassis = chassis;
> +    p_ctx->flow_table = flow_table;
> +    p_ctx->active_tunnels = &rt_data->active_tunnels;
> +    p_ctx->local_datapaths = &rt_data->local_datapaths;
> +    p_ctx->local_lports = &rt_data->local_lports;
> +    p_ctx->ct_zones = ct_zones;
> +    p_ctx->mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
> +}
> +
>  static void init_lflow_ctx(struct engine_node *node,
>                             struct ed_type_runtime_data *rt_data,
>                             struct ed_type_flow_output *fo,
> @@ -1317,17 +1379,6 @@ en_flow_output_run(struct engine_node *node, void
*data)
>  {
>      struct ed_type_runtime_data *rt_data =
>          engine_get_input_data("runtime_data", node);
> -    struct hmap *local_datapaths = &rt_data->local_datapaths;
> -    struct sset *local_lports = &rt_data->local_lports;
> -    struct sset *active_tunnels = &rt_data->active_tunnels;
> -
> -    struct ed_type_ct_zones *ct_zones_data =
> -        engine_get_input_data("ct_zones", node);
> -    struct simap *ct_zones = &ct_zones_data->current;
> -
> -    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
> -        engine_get_input_data("mff_ovn_geneve", node);
> -    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
>
>      struct ovsrec_open_vswitch_table *ovs_table =
>          (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
> @@ -1367,37 +1418,15 @@ en_flow_output_run(struct engine_node *node, void
*data)
>          lflow_resource_clear(lfrr);
>      }
>
> -    struct ovsdb_idl_index *sbrec_port_binding_by_name =
> -        engine_ovsdb_node_get_index(
> -                engine_get_input("SB_port_binding", node),
> -                "name");
> -
>      *conj_id_ofs = 1;
>      struct lflow_ctx l_ctx;
>      init_lflow_ctx(node, rt_data, fo, &l_ctx);
>      lflow_run(&l_ctx);
>
> -    struct sbrec_multicast_group_table *multicast_group_table =
> -        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
> -            engine_get_input("SB_multicast_group", node));
> -
> -    struct sbrec_port_binding_table *port_binding_table =
> -        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
> -            engine_get_input("SB_port_binding", node));
> -
> -    struct sbrec_chassis_table *chassis_table =
> -        (struct sbrec_chassis_table *)EN_OVSDB_GET(
> -            engine_get_input("SB_chassis", node));
> +    struct physical_ctx p_ctx;
> +    init_physical_ctx(node, rt_data, &fo->flow_table, &p_ctx);
>
> -    physical_run(sbrec_port_binding_by_name,
> -                 multicast_group_table,
> -                 port_binding_table,
> -                 chassis_table,
> -                 mff_ovn_geneve,
> -                 br_int, chassis, ct_zones,
> -                 local_datapaths, local_lports,
> -                 active_tunnels,
> -                 flow_table);
> +    physical_run(&p_ctx);
>
>      engine_set_node_state(node, EN_UPDATED);
>  }
> @@ -1453,48 +1482,10 @@ flow_output_sb_port_binding_handler(struct
engine_node *node, void *data)
>  {
>      struct ed_type_runtime_data *rt_data =
>          engine_get_input_data("runtime_data", node);
> -    struct hmap *local_datapaths = &rt_data->local_datapaths;
> -    struct sset *active_tunnels = &rt_data->active_tunnels;
> -
> -    struct ed_type_ct_zones *ct_zones_data =
> -        engine_get_input_data("ct_zones", node);
> -    struct simap *ct_zones = &ct_zones_data->current;
> -
> -    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
> -        engine_get_input_data("mff_ovn_geneve", node);
> -    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
> -
> -    struct ovsrec_open_vswitch_table *ovs_table =
> -        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
> -            engine_get_input("OVS_open_vswitch", node));
> -    struct ovsrec_bridge_table *bridge_table =
> -        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
> -            engine_get_input("OVS_bridge", node));
> -    const struct ovsrec_bridge *br_int = get_br_int(bridge_table,
ovs_table);
> -    const char *chassis_id = chassis_get_id();
> -
> -    struct ovsdb_idl_index *sbrec_chassis_by_name =
> -        engine_ovsdb_node_get_index(
> -                engine_get_input("SB_chassis", node),
> -                "name");
> -    const struct sbrec_chassis *chassis = NULL;
> -    if (chassis_id) {
> -        chassis = chassis_lookup_by_name(sbrec_chassis_by_name,
chassis_id);
> -    }
> -    ovs_assert(br_int && chassis);
>
>      struct ed_type_flow_output *fo = data;
>      struct ovn_desired_flow_table *flow_table = &fo->flow_table;
>
> -    struct ovsdb_idl_index *sbrec_port_binding_by_name =
> -        engine_ovsdb_node_get_index(
> -                engine_get_input("SB_port_binding", node),
> -                "name");
> -
> -    struct sbrec_port_binding_table *port_binding_table =
> -        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
> -            engine_get_input("SB_port_binding", node));
> -
>      /* XXX: now we handle port-binding changes for physical flow
processing
>       * only, but port-binding change can have impact to logical flow
>       * processing, too, in below circumstances:
> @@ -1542,11 +1533,10 @@ flow_output_sb_port_binding_handler(struct
engine_node *node, void *data)
>       * names and the lflows that uses them, and reprocess the related
lflows
>       * when related port-bindings change.
>       */
> -    physical_handle_port_binding_changes(
> -            sbrec_port_binding_by_name,
> -            port_binding_table, mff_ovn_geneve,
> -            chassis, ct_zones, local_datapaths,
> -            active_tunnels, flow_table);
> +    struct physical_ctx p_ctx;
> +    init_physical_ctx(node, rt_data, flow_table, &p_ctx);
> +
> +    physical_handle_port_binding_changes(&p_ctx);
>
>      engine_set_node_state(node, EN_UPDATED);
>      return true;
> @@ -1557,45 +1547,14 @@ flow_output_sb_multicast_group_handler(struct
engine_node *node, void *data)
>  {
>      struct ed_type_runtime_data *rt_data =
>          engine_get_input_data("runtime_data", node);
> -    struct hmap *local_datapaths = &rt_data->local_datapaths;
> -
> -    struct ed_type_ct_zones *ct_zones_data =
> -        engine_get_input_data("ct_zones", node);
> -    struct simap *ct_zones = &ct_zones_data->current;
> -
> -    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
> -        engine_get_input_data("mff_ovn_geneve", node);
> -    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
> -
> -    struct ovsrec_open_vswitch_table *ovs_table =
> -        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
> -            engine_get_input("OVS_open_vswitch", node));
> -    struct ovsrec_bridge_table *bridge_table =
> -        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
> -            engine_get_input("OVS_bridge", node));
> -    const struct ovsrec_bridge *br_int = get_br_int(bridge_table,
ovs_table);
> -    const char *chassis_id = chassis_get_id();
> -
> -    struct ovsdb_idl_index *sbrec_chassis_by_name =
> -        engine_ovsdb_node_get_index(
> -                engine_get_input("SB_chassis", node),
> -                "name");
> -    const struct sbrec_chassis *chassis = NULL;
> -    if (chassis_id) {
> -        chassis = chassis_lookup_by_name(sbrec_chassis_by_name,
chassis_id);
> -    }
> -    ovs_assert(br_int && chassis);
>
>      struct ed_type_flow_output *fo = data;
>      struct ovn_desired_flow_table *flow_table = &fo->flow_table;
>
> -    struct sbrec_multicast_group_table *multicast_group_table =
> -        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
> -            engine_get_input("SB_multicast_group", node));
> +    struct physical_ctx p_ctx;
> +    init_physical_ctx(node, rt_data, flow_table, &p_ctx);
>
> -    physical_handle_mc_group_changes(multicast_group_table,
> -            mff_ovn_geneve, chassis, ct_zones, local_datapaths,
> -            flow_table);
> +    physical_handle_mc_group_changes(&p_ctx);
>
>      engine_set_node_state(node, EN_UPDATED);
>      return true;
> diff --git a/controller/physical.c b/controller/physical.c
> index 500d41994..8fb84e7f8 100644
> --- a/controller/physical.c
> +++ b/controller/physical.c
> @@ -1396,72 +1396,50 @@ update_ofports(struct simap *old, struct simap
*new)
>      return changed;
>  }
>
> -void physical_handle_port_binding_changes(
> -        struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -        const struct sbrec_port_binding_table *pb_table,
> -        enum mf_field_id mff_ovn_geneve,
> -        const struct sbrec_chassis *chassis,
> -        const struct simap *ct_zones,
> -        struct hmap *local_datapaths,
> -        struct sset *active_tunnels,
> -        struct ovn_desired_flow_table *flow_table)
> +void physical_handle_port_binding_changes(struct physical_ctx *p_ctx)
>  {
>      const struct sbrec_port_binding *binding;
>      struct ofpbuf ofpacts;
>      ofpbuf_init(&ofpacts, 0);
> -    SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding, pb_table) {
> +    SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding,
> +
p_ctx->port_binding_table) {
>          if (sbrec_port_binding_is_deleted(binding)) {
> -            ofctrl_remove_flows(flow_table, &binding->header_.uuid);
> +            ofctrl_remove_flows(p_ctx->flow_table,
&binding->header_.uuid);
>          } else {
>              if (!sbrec_port_binding_is_new(binding)) {
> -                ofctrl_remove_flows(flow_table, &binding->header_.uuid);
> +                ofctrl_remove_flows(p_ctx->flow_table,
&binding->header_.uuid);
>              }
> -            consider_port_binding(sbrec_port_binding_by_name,
> -                                  mff_ovn_geneve, ct_zones,
> -                                  active_tunnels, local_datapaths,
> -                                  binding, chassis,
> -                                  flow_table, &ofpacts);
> +            consider_port_binding(p_ctx->sbrec_port_binding_by_name,
> +                                  p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
> +                                  p_ctx->active_tunnels,
> +                                  p_ctx->local_datapaths,
> +                                  binding, p_ctx->chassis,
> +                                  p_ctx->flow_table, &ofpacts);
>          }
>      }
>      ofpbuf_uninit(&ofpacts);
>  }
>
>  void
> -physical_handle_mc_group_changes(
> -        const struct sbrec_multicast_group_table *multicast_group_table,
> -        enum mf_field_id mff_ovn_geneve,
> -        const struct sbrec_chassis *chassis,
> -        const struct simap *ct_zones,
> -        const struct hmap *local_datapaths,
> -        struct ovn_desired_flow_table *flow_table)
> +physical_handle_mc_group_changes(struct physical_ctx *p_ctx)
>  {
>      const struct sbrec_multicast_group *mc;
> -    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc,
multicast_group_table) {
> +    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc,
p_ctx->mc_group_table) {
>          if (sbrec_multicast_group_is_deleted(mc)) {
> -            ofctrl_remove_flows(flow_table, &mc->header_.uuid);
> +            ofctrl_remove_flows(p_ctx->flow_table, &mc->header_.uuid);
>          } else {
>              if (!sbrec_multicast_group_is_new(mc)) {
> -                ofctrl_remove_flows(flow_table, &mc->header_.uuid);
> +                ofctrl_remove_flows(p_ctx->flow_table,
&mc->header_.uuid);
>              }
> -            consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths,
> -                              chassis, mc, flow_table);
> +            consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
> +                              p_ctx->local_datapaths,
> +                              p_ctx->chassis, mc, p_ctx->flow_table);
>          }
>      }
>  }
>
>  void
> -physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -             const struct sbrec_multicast_group_table
*multicast_group_table,
> -             const struct sbrec_port_binding_table *port_binding_table,
> -             const struct sbrec_chassis_table *chassis_table,
> -             enum mf_field_id mff_ovn_geneve,
> -             const struct ovsrec_bridge *br_int,
> -             const struct sbrec_chassis *chassis,
> -             const struct simap *ct_zones,
> -             const struct hmap *local_datapaths,
> -             const struct sset *local_lports,
> -             const struct sset *active_tunnels,
> -             struct ovn_desired_flow_table *flow_table)
> +physical_run(struct physical_ctx *p_ctx)
>  {
>      if (!hc_uuid) {
>          hc_uuid = xmalloc(sizeof(struct uuid));
> @@ -1475,16 +1453,17 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>          SIMAP_INITIALIZER(&new_localvif_to_ofport);
>      struct simap new_tunnel_to_ofport =
>          SIMAP_INITIALIZER(&new_tunnel_to_ofport);
> -    for (int i = 0; i < br_int->n_ports; i++) {
> -        const struct ovsrec_port *port_rec = br_int->ports[i];
> -        if (!strcmp(port_rec->name, br_int->name)) {
> +    for (int i = 0; i < p_ctx->br_int->n_ports; i++) {
> +        const struct ovsrec_port *port_rec = p_ctx->br_int->ports[i];
> +        if (!strcmp(port_rec->name, p_ctx->br_int->name)) {
>              continue;
>          }
>
>          const char *tunnel_id = smap_get(&port_rec->external_ids,
>                                           "ovn-chassis-id");
> -        if (tunnel_id &&
> -                encaps_tunnel_id_match(tunnel_id, chassis->name, NULL)) {
> +        if (tunnel_id && encaps_tunnel_id_match(tunnel_id,
> +                                                p_ctx->chassis->name,
> +                                                NULL)) {
>              continue;
>          }
>
> @@ -1520,7 +1499,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>                  enum chassis_tunnel_type tunnel_type;
>                  if (!strcmp(iface_rec->type, "geneve")) {
>                      tunnel_type = GENEVE;
> -                    if (!mff_ovn_geneve) {
> +                    if (!p_ctx->mff_ovn_geneve) {
>                          continue;
>                      }
>                  } else if (!strcmp(iface_rec->type, "stt")) {
> @@ -1599,24 +1578,26 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      struct ofpbuf ofpacts;
>      ofpbuf_init(&ofpacts, 0);
>
> -    put_chassis_mac_conj_id_flow(chassis_table, chassis, &ofpacts,
flow_table);
> +    put_chassis_mac_conj_id_flow(p_ctx->chassis_table, p_ctx->chassis,
> +                                 &ofpacts, p_ctx->flow_table);
>
>      /* Set up flows in table 0 for physical-to-logical translation and
in table
>       * 64 for logical-to-physical translation. */
>      const struct sbrec_port_binding *binding;
> -    SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) {
> -        consider_port_binding(sbrec_port_binding_by_name,
> -                              mff_ovn_geneve, ct_zones,
> -                              active_tunnels, local_datapaths,
> -                              binding, chassis,
> -                              flow_table, &ofpacts);
> +    SBREC_PORT_BINDING_TABLE_FOR_EACH (binding,
p_ctx->port_binding_table) {
> +        consider_port_binding(p_ctx->sbrec_port_binding_by_name,
> +                              p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
> +                              p_ctx->active_tunnels,
p_ctx->local_datapaths,
> +                              binding, p_ctx->chassis,
> +                              p_ctx->flow_table, &ofpacts);
>      }
>
>      /* Handle output to multicast groups, in tables 32 and 33. */
>      const struct sbrec_multicast_group *mc;
> -    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, multicast_group_table) {
> -        consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths,
> -                          chassis, mc, flow_table);
> +    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, p_ctx->mc_group_table) {
> +        consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
> +                          p_ctx->local_datapaths, p_ctx->chassis,
> +                          mc, p_ctx->flow_table);
>      }
>
>      /* Table 0, priority 100.
> @@ -1637,9 +1618,9 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>          ofpbuf_clear(&ofpacts);
>          if (tun->type == GENEVE) {
>              put_move(MFF_TUN_ID, 0,  MFF_LOG_DATAPATH, 0, 24, &ofpacts);
> -            put_move(mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15,
> +            put_move(p_ctx->mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15,
>                       &ofpacts);
> -            put_move(mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16,
> +            put_move(p_ctx->mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16,
>                       &ofpacts);
>          } else if (tun->type == STT) {
>              put_move(MFF_TUN_ID, 40, MFF_LOG_INPORT,   0, 15, &ofpacts);
> @@ -1654,7 +1635,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>
>          put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
>
> -        ofctrl_add_flow(flow_table, OFTABLE_PHY_TO_LOG, 100, 0, &match,
> +        ofctrl_add_flow(p_ctx->flow_table, OFTABLE_PHY_TO_LOG, 100, 0,
&match,
>                          &ofpacts, hc_uuid);
>      }
>
> @@ -1668,7 +1649,8 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>              continue;
>          }
>
> -        SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) {
> +        SBREC_PORT_BINDING_TABLE_FOR_EACH (binding,
> +                                           p_ctx->port_binding_table) {
>              struct match match = MATCH_CATCHALL_INITIALIZER;
>
>              if (!binding->chassis ||
> @@ -1688,7 +1670,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>              put_load(1, MFF_LOG_FLAGS, MLF_RCV_FROM_VXLAN_BIT, 1,
&ofpacts);
>              put_resubmit(OFTABLE_LOG_INGRESS_PIPELINE, &ofpacts);
>
> -            ofctrl_add_flow(flow_table, OFTABLE_PHY_TO_LOG, 100,
> +            ofctrl_add_flow(p_ctx->flow_table, OFTABLE_PHY_TO_LOG, 100,
>                              binding->header_.uuid.parts[0],
>                              &match, &ofpacts, hc_uuid);
>          }
> @@ -1710,7 +1692,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      /* Resubmit to table 33. */
>      ofpbuf_clear(&ofpacts);
>      put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
> -    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
> +    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
>                      &match, &ofpacts, hc_uuid);
>
>      /* Table 32, priority 150.
> @@ -1724,7 +1706,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      /* Resubmit to table 33. */
>      ofpbuf_clear(&ofpacts);
>      put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
> -    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
> +    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
>                      &match, &ofpacts, hc_uuid);
>
>      /* Table 32, priority 150.
> @@ -1738,16 +1720,16 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      ofpbuf_clear(&ofpacts);
>      put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
>      const char *localport;
> -    SSET_FOR_EACH (localport, local_lports) {
> +    SSET_FOR_EACH (localport, p_ctx->local_lports) {
>          /* Iterate over all local logical ports and insert a drop
>           * rule with higher priority for every localport in this
>           * datapath. */
>          const struct sbrec_port_binding *pb = lport_lookup_by_name(
> -            sbrec_port_binding_by_name, localport);
> +            p_ctx->sbrec_port_binding_by_name, localport);
>          if (pb && !strcmp(pb->type, "localport")) {
>              match_set_reg(&match, MFF_LOG_INPORT - MFF_REG0,
pb->tunnel_key);
>              match_set_metadata(&match, htonll(pb->datapath->tunnel_key));
> -            ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150,
> +            ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT,
150,
>                              pb->header_.uuid.parts[0],
>                              &match, &ofpacts, hc_uuid);
>          }
> @@ -1761,8 +1743,8 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      match_init_catchall(&match);
>      ofpbuf_clear(&ofpacts);
>      put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
> -    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0, &match,
&ofpacts,
> -                    hc_uuid);
> +    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0,
&match,
> +                    &ofpacts, hc_uuid);
>
>      /* Table 34, Priority 0.
>       * =======================
> @@ -1776,7 +1758,7 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>          put_load(0, MFF_REG0 + i, 0, 32, &ofpacts);
>      }
>      put_resubmit(OFTABLE_LOG_EGRESS_PIPELINE, &ofpacts);
> -    ofctrl_add_flow(flow_table, OFTABLE_CHECK_LOOPBACK, 0, 0, &match,
> +    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_CHECK_LOOPBACK, 0, 0,
&match,
>                      &ofpacts, hc_uuid);
>
>      /* Table 64, Priority 0.
> @@ -1787,8 +1769,8 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      match_init_catchall(&match);
>      ofpbuf_clear(&ofpacts);
>      put_resubmit(OFTABLE_LOG_TO_PHY, &ofpacts);
> -    ofctrl_add_flow(flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match,
&ofpacts,
> -                    hc_uuid);
> +    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match,
> +                    &ofpacts, hc_uuid);
>
>      ofpbuf_uninit(&ofpacts);
>
> diff --git a/controller/physical.h b/controller/physical.h
> index c93f6b1c0..477a1cbad 100644
> --- a/controller/physical.h
> +++ b/controller/physical.h
> @@ -42,34 +42,24 @@ struct sset;
>  #define OVN_GENEVE_TYPE 0x80     /* Critical option. */
>  #define OVN_GENEVE_LEN 4
>
> +struct physical_ctx {
> +    struct ovsdb_idl_index *sbrec_port_binding_by_name;
> +    const struct sbrec_port_binding_table *port_binding_table;
> +    const struct sbrec_multicast_group_table *mc_group_table;
> +    const struct ovsrec_bridge *br_int;
> +    const struct sbrec_chassis_table *chassis_table;
> +    const struct sbrec_chassis *chassis;
> +    struct ovn_desired_flow_table *flow_table;
> +    const struct sset *active_tunnels;
> +    struct hmap *local_datapaths;
> +    struct sset *local_lports;
> +    const struct simap *ct_zones;
> +    enum mf_field_id mff_ovn_geneve;
> +};
> +
>  void physical_register_ovs_idl(struct ovsdb_idl *);
> -void physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -                  const struct sbrec_multicast_group_table *,
> -                  const struct sbrec_port_binding_table *,
> -                  const struct sbrec_chassis_table *chassis_table,
> -                  enum mf_field_id mff_ovn_geneve,
> -                  const struct ovsrec_bridge *br_int,
> -                  const struct sbrec_chassis *chassis,
> -                  const struct simap *ct_zones,
> -                  const struct hmap *local_datapaths,
> -                  const struct sset *local_lports,
> -                  const struct sset *active_tunnels,
> -                  struct ovn_desired_flow_table *);
> -void physical_handle_port_binding_changes(
> -        struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -        const struct sbrec_port_binding_table *,
> -        enum mf_field_id mff_ovn_geneve,
> -        const struct sbrec_chassis *,
> -        const struct simap *ct_zones,
> -        struct hmap *local_datapaths,
> -        struct sset *active_tunnels,
> -        struct ovn_desired_flow_table *);
> +void physical_run(struct physical_ctx *);
> +void physical_handle_port_binding_changes(struct physical_ctx *);
>
> -void physical_handle_mc_group_changes(
> -        const struct sbrec_multicast_group_table *,
> -        enum mf_field_id mff_ovn_geneve,
> -        const struct sbrec_chassis *,
> -        const struct simap *ct_zones,
> -        const struct hmap *local_datapaths,
> -        struct ovn_desired_flow_table *);
> +void physical_handle_mc_group_changes(struct physical_ctx *);
>  #endif /* controller/physical.h */
> --
> 2.24.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Patch
diff mbox series

diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 4942df6c4..390057ee2 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -1213,6 +1213,68 @@  struct ed_type_flow_output {
     struct lflow_resource_ref lflow_resource_ref;
 };
 
+static void init_physical_ctx(struct engine_node *node,
+                              struct ed_type_runtime_data *rt_data,
+                              struct ovn_desired_flow_table *flow_table,
+                              struct physical_ctx *p_ctx)
+{
+    struct ovsdb_idl_index *sbrec_port_binding_by_name =
+        engine_ovsdb_node_get_index(
+                engine_get_input("SB_port_binding", node),
+                "name");
+
+    struct sbrec_multicast_group_table *multicast_group_table =
+        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
+            engine_get_input("SB_multicast_group", node));
+
+    struct sbrec_port_binding_table *port_binding_table =
+        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
+            engine_get_input("SB_port_binding", node));
+
+    struct sbrec_chassis_table *chassis_table =
+        (struct sbrec_chassis_table *)EN_OVSDB_GET(
+            engine_get_input("SB_chassis", node));
+
+    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
+        engine_get_input_data("mff_ovn_geneve", node);
+
+    struct ovsrec_open_vswitch_table *ovs_table =
+        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
+            engine_get_input("OVS_open_vswitch", node));
+    struct ovsrec_bridge_table *bridge_table =
+        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
+            engine_get_input("OVS_bridge", node));
+    const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
+    const char *chassis_id = chassis_get_id();
+    const struct sbrec_chassis *chassis = NULL;
+    struct ovsdb_idl_index *sbrec_chassis_by_name =
+        engine_ovsdb_node_get_index(
+                engine_get_input("SB_chassis", node),
+                "name");
+    if (chassis_id) {
+        chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
+    }
+
+    ovs_assert(br_int && chassis);
+
+    struct ed_type_ct_zones *ct_zones_data =
+        engine_get_input_data("ct_zones", node);
+    struct simap *ct_zones = &ct_zones_data->current;
+
+    p_ctx->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
+    p_ctx->port_binding_table = port_binding_table;
+    p_ctx->mc_group_table = multicast_group_table;
+    p_ctx->br_int = br_int;
+    p_ctx->chassis_table = chassis_table;
+    p_ctx->chassis = chassis;
+    p_ctx->flow_table = flow_table;
+    p_ctx->active_tunnels = &rt_data->active_tunnels;
+    p_ctx->local_datapaths = &rt_data->local_datapaths;
+    p_ctx->local_lports = &rt_data->local_lports;
+    p_ctx->ct_zones = ct_zones;
+    p_ctx->mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
+}
+
 static void init_lflow_ctx(struct engine_node *node,
                            struct ed_type_runtime_data *rt_data,
                            struct ed_type_flow_output *fo,
@@ -1317,17 +1379,6 @@  en_flow_output_run(struct engine_node *node, void *data)
 {
     struct ed_type_runtime_data *rt_data =
         engine_get_input_data("runtime_data", node);
-    struct hmap *local_datapaths = &rt_data->local_datapaths;
-    struct sset *local_lports = &rt_data->local_lports;
-    struct sset *active_tunnels = &rt_data->active_tunnels;
-
-    struct ed_type_ct_zones *ct_zones_data =
-        engine_get_input_data("ct_zones", node);
-    struct simap *ct_zones = &ct_zones_data->current;
-
-    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
-        engine_get_input_data("mff_ovn_geneve", node);
-    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
 
     struct ovsrec_open_vswitch_table *ovs_table =
         (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
@@ -1367,37 +1418,15 @@  en_flow_output_run(struct engine_node *node, void *data)
         lflow_resource_clear(lfrr);
     }
 
-    struct ovsdb_idl_index *sbrec_port_binding_by_name =
-        engine_ovsdb_node_get_index(
-                engine_get_input("SB_port_binding", node),
-                "name");
-
     *conj_id_ofs = 1;
     struct lflow_ctx l_ctx;
     init_lflow_ctx(node, rt_data, fo, &l_ctx);
     lflow_run(&l_ctx);
 
-    struct sbrec_multicast_group_table *multicast_group_table =
-        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
-            engine_get_input("SB_multicast_group", node));
-
-    struct sbrec_port_binding_table *port_binding_table =
-        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
-            engine_get_input("SB_port_binding", node));
-
-    struct sbrec_chassis_table *chassis_table =
-        (struct sbrec_chassis_table *)EN_OVSDB_GET(
-            engine_get_input("SB_chassis", node));
+    struct physical_ctx p_ctx;
+    init_physical_ctx(node, rt_data, &fo->flow_table, &p_ctx);
 
-    physical_run(sbrec_port_binding_by_name,
-                 multicast_group_table,
-                 port_binding_table,
-                 chassis_table,
-                 mff_ovn_geneve,
-                 br_int, chassis, ct_zones,
-                 local_datapaths, local_lports,
-                 active_tunnels,
-                 flow_table);
+    physical_run(&p_ctx);
 
     engine_set_node_state(node, EN_UPDATED);
 }
@@ -1453,48 +1482,10 @@  flow_output_sb_port_binding_handler(struct engine_node *node, void *data)
 {
     struct ed_type_runtime_data *rt_data =
         engine_get_input_data("runtime_data", node);
-    struct hmap *local_datapaths = &rt_data->local_datapaths;
-    struct sset *active_tunnels = &rt_data->active_tunnels;
-
-    struct ed_type_ct_zones *ct_zones_data =
-        engine_get_input_data("ct_zones", node);
-    struct simap *ct_zones = &ct_zones_data->current;
-
-    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
-        engine_get_input_data("mff_ovn_geneve", node);
-    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
-
-    struct ovsrec_open_vswitch_table *ovs_table =
-        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
-            engine_get_input("OVS_open_vswitch", node));
-    struct ovsrec_bridge_table *bridge_table =
-        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
-            engine_get_input("OVS_bridge", node));
-    const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
-    const char *chassis_id = chassis_get_id();
-
-    struct ovsdb_idl_index *sbrec_chassis_by_name =
-        engine_ovsdb_node_get_index(
-                engine_get_input("SB_chassis", node),
-                "name");
-    const struct sbrec_chassis *chassis = NULL;
-    if (chassis_id) {
-        chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
-    }
-    ovs_assert(br_int && chassis);
 
     struct ed_type_flow_output *fo = data;
     struct ovn_desired_flow_table *flow_table = &fo->flow_table;
 
-    struct ovsdb_idl_index *sbrec_port_binding_by_name =
-        engine_ovsdb_node_get_index(
-                engine_get_input("SB_port_binding", node),
-                "name");
-
-    struct sbrec_port_binding_table *port_binding_table =
-        (struct sbrec_port_binding_table *)EN_OVSDB_GET(
-            engine_get_input("SB_port_binding", node));
-
     /* XXX: now we handle port-binding changes for physical flow processing
      * only, but port-binding change can have impact to logical flow
      * processing, too, in below circumstances:
@@ -1542,11 +1533,10 @@  flow_output_sb_port_binding_handler(struct engine_node *node, void *data)
      * names and the lflows that uses them, and reprocess the related lflows
      * when related port-bindings change.
      */
-    physical_handle_port_binding_changes(
-            sbrec_port_binding_by_name,
-            port_binding_table, mff_ovn_geneve,
-            chassis, ct_zones, local_datapaths,
-            active_tunnels, flow_table);
+    struct physical_ctx p_ctx;
+    init_physical_ctx(node, rt_data, flow_table, &p_ctx);
+
+    physical_handle_port_binding_changes(&p_ctx);
 
     engine_set_node_state(node, EN_UPDATED);
     return true;
@@ -1557,45 +1547,14 @@  flow_output_sb_multicast_group_handler(struct engine_node *node, void *data)
 {
     struct ed_type_runtime_data *rt_data =
         engine_get_input_data("runtime_data", node);
-    struct hmap *local_datapaths = &rt_data->local_datapaths;
-
-    struct ed_type_ct_zones *ct_zones_data =
-        engine_get_input_data("ct_zones", node);
-    struct simap *ct_zones = &ct_zones_data->current;
-
-    struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
-        engine_get_input_data("mff_ovn_geneve", node);
-    enum mf_field_id mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
-
-    struct ovsrec_open_vswitch_table *ovs_table =
-        (struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
-            engine_get_input("OVS_open_vswitch", node));
-    struct ovsrec_bridge_table *bridge_table =
-        (struct ovsrec_bridge_table *)EN_OVSDB_GET(
-            engine_get_input("OVS_bridge", node));
-    const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
-    const char *chassis_id = chassis_get_id();
-
-    struct ovsdb_idl_index *sbrec_chassis_by_name =
-        engine_ovsdb_node_get_index(
-                engine_get_input("SB_chassis", node),
-                "name");
-    const struct sbrec_chassis *chassis = NULL;
-    if (chassis_id) {
-        chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
-    }
-    ovs_assert(br_int && chassis);
 
     struct ed_type_flow_output *fo = data;
     struct ovn_desired_flow_table *flow_table = &fo->flow_table;
 
-    struct sbrec_multicast_group_table *multicast_group_table =
-        (struct sbrec_multicast_group_table *)EN_OVSDB_GET(
-            engine_get_input("SB_multicast_group", node));
+    struct physical_ctx p_ctx;
+    init_physical_ctx(node, rt_data, flow_table, &p_ctx);
 
-    physical_handle_mc_group_changes(multicast_group_table,
-            mff_ovn_geneve, chassis, ct_zones, local_datapaths,
-            flow_table);
+    physical_handle_mc_group_changes(&p_ctx);
 
     engine_set_node_state(node, EN_UPDATED);
     return true;
diff --git a/controller/physical.c b/controller/physical.c
index 500d41994..8fb84e7f8 100644
--- a/controller/physical.c
+++ b/controller/physical.c
@@ -1396,72 +1396,50 @@  update_ofports(struct simap *old, struct simap *new)
     return changed;
 }
 
-void physical_handle_port_binding_changes(
-        struct ovsdb_idl_index *sbrec_port_binding_by_name,
-        const struct sbrec_port_binding_table *pb_table,
-        enum mf_field_id mff_ovn_geneve,
-        const struct sbrec_chassis *chassis,
-        const struct simap *ct_zones,
-        struct hmap *local_datapaths,
-        struct sset *active_tunnels,
-        struct ovn_desired_flow_table *flow_table)
+void physical_handle_port_binding_changes(struct physical_ctx *p_ctx)
 {
     const struct sbrec_port_binding *binding;
     struct ofpbuf ofpacts;
     ofpbuf_init(&ofpacts, 0);
-    SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding, pb_table) {
+    SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (binding,
+                                               p_ctx->port_binding_table) {
         if (sbrec_port_binding_is_deleted(binding)) {
-            ofctrl_remove_flows(flow_table, &binding->header_.uuid);
+            ofctrl_remove_flows(p_ctx->flow_table, &binding->header_.uuid);
         } else {
             if (!sbrec_port_binding_is_new(binding)) {
-                ofctrl_remove_flows(flow_table, &binding->header_.uuid);
+                ofctrl_remove_flows(p_ctx->flow_table, &binding->header_.uuid);
             }
-            consider_port_binding(sbrec_port_binding_by_name,
-                                  mff_ovn_geneve, ct_zones,
-                                  active_tunnels, local_datapaths,
-                                  binding, chassis,
-                                  flow_table, &ofpacts);
+            consider_port_binding(p_ctx->sbrec_port_binding_by_name,
+                                  p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
+                                  p_ctx->active_tunnels,
+                                  p_ctx->local_datapaths,
+                                  binding, p_ctx->chassis,
+                                  p_ctx->flow_table, &ofpacts);
         }
     }
     ofpbuf_uninit(&ofpacts);
 }
 
 void
-physical_handle_mc_group_changes(
-        const struct sbrec_multicast_group_table *multicast_group_table,
-        enum mf_field_id mff_ovn_geneve,
-        const struct sbrec_chassis *chassis,
-        const struct simap *ct_zones,
-        const struct hmap *local_datapaths,
-        struct ovn_desired_flow_table *flow_table)
+physical_handle_mc_group_changes(struct physical_ctx *p_ctx)
 {
     const struct sbrec_multicast_group *mc;
-    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc, multicast_group_table) {
+    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH_TRACKED (mc, p_ctx->mc_group_table) {
         if (sbrec_multicast_group_is_deleted(mc)) {
-            ofctrl_remove_flows(flow_table, &mc->header_.uuid);
+            ofctrl_remove_flows(p_ctx->flow_table, &mc->header_.uuid);
         } else {
             if (!sbrec_multicast_group_is_new(mc)) {
-                ofctrl_remove_flows(flow_table, &mc->header_.uuid);
+                ofctrl_remove_flows(p_ctx->flow_table, &mc->header_.uuid);
             }
-            consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths,
-                              chassis, mc, flow_table);
+            consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
+                              p_ctx->local_datapaths,
+                              p_ctx->chassis, mc, p_ctx->flow_table);
         }
     }
 }
 
 void
-physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
-             const struct sbrec_multicast_group_table *multicast_group_table,
-             const struct sbrec_port_binding_table *port_binding_table,
-             const struct sbrec_chassis_table *chassis_table,
-             enum mf_field_id mff_ovn_geneve,
-             const struct ovsrec_bridge *br_int,
-             const struct sbrec_chassis *chassis,
-             const struct simap *ct_zones,
-             const struct hmap *local_datapaths,
-             const struct sset *local_lports,
-             const struct sset *active_tunnels,
-             struct ovn_desired_flow_table *flow_table)
+physical_run(struct physical_ctx *p_ctx)
 {
     if (!hc_uuid) {
         hc_uuid = xmalloc(sizeof(struct uuid));
@@ -1475,16 +1453,17 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
         SIMAP_INITIALIZER(&new_localvif_to_ofport);
     struct simap new_tunnel_to_ofport =
         SIMAP_INITIALIZER(&new_tunnel_to_ofport);
-    for (int i = 0; i < br_int->n_ports; i++) {
-        const struct ovsrec_port *port_rec = br_int->ports[i];
-        if (!strcmp(port_rec->name, br_int->name)) {
+    for (int i = 0; i < p_ctx->br_int->n_ports; i++) {
+        const struct ovsrec_port *port_rec = p_ctx->br_int->ports[i];
+        if (!strcmp(port_rec->name, p_ctx->br_int->name)) {
             continue;
         }
 
         const char *tunnel_id = smap_get(&port_rec->external_ids,
                                          "ovn-chassis-id");
-        if (tunnel_id &&
-                encaps_tunnel_id_match(tunnel_id, chassis->name, NULL)) {
+        if (tunnel_id && encaps_tunnel_id_match(tunnel_id,
+                                                p_ctx->chassis->name,
+                                                NULL)) {
             continue;
         }
 
@@ -1520,7 +1499,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
                 enum chassis_tunnel_type tunnel_type;
                 if (!strcmp(iface_rec->type, "geneve")) {
                     tunnel_type = GENEVE;
-                    if (!mff_ovn_geneve) {
+                    if (!p_ctx->mff_ovn_geneve) {
                         continue;
                     }
                 } else if (!strcmp(iface_rec->type, "stt")) {
@@ -1599,24 +1578,26 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     struct ofpbuf ofpacts;
     ofpbuf_init(&ofpacts, 0);
 
-    put_chassis_mac_conj_id_flow(chassis_table, chassis, &ofpacts, flow_table);
+    put_chassis_mac_conj_id_flow(p_ctx->chassis_table, p_ctx->chassis,
+                                 &ofpacts, p_ctx->flow_table);
 
     /* Set up flows in table 0 for physical-to-logical translation and in table
      * 64 for logical-to-physical translation. */
     const struct sbrec_port_binding *binding;
-    SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) {
-        consider_port_binding(sbrec_port_binding_by_name,
-                              mff_ovn_geneve, ct_zones,
-                              active_tunnels, local_datapaths,
-                              binding, chassis,
-                              flow_table, &ofpacts);
+    SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, p_ctx->port_binding_table) {
+        consider_port_binding(p_ctx->sbrec_port_binding_by_name,
+                              p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
+                              p_ctx->active_tunnels, p_ctx->local_datapaths,
+                              binding, p_ctx->chassis,
+                              p_ctx->flow_table, &ofpacts);
     }
 
     /* Handle output to multicast groups, in tables 32 and 33. */
     const struct sbrec_multicast_group *mc;
-    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, multicast_group_table) {
-        consider_mc_group(mff_ovn_geneve, ct_zones, local_datapaths,
-                          chassis, mc, flow_table);
+    SBREC_MULTICAST_GROUP_TABLE_FOR_EACH (mc, p_ctx->mc_group_table) {
+        consider_mc_group(p_ctx->mff_ovn_geneve, p_ctx->ct_zones,
+                          p_ctx->local_datapaths, p_ctx->chassis,
+                          mc, p_ctx->flow_table);
     }
 
     /* Table 0, priority 100.
@@ -1637,9 +1618,9 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
         ofpbuf_clear(&ofpacts);
         if (tun->type == GENEVE) {
             put_move(MFF_TUN_ID, 0,  MFF_LOG_DATAPATH, 0, 24, &ofpacts);
-            put_move(mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15,
+            put_move(p_ctx->mff_ovn_geneve, 16, MFF_LOG_INPORT, 0, 15,
                      &ofpacts);
-            put_move(mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16,
+            put_move(p_ctx->mff_ovn_geneve, 0, MFF_LOG_OUTPORT, 0, 16,
                      &ofpacts);
         } else if (tun->type == STT) {
             put_move(MFF_TUN_ID, 40, MFF_LOG_INPORT,   0, 15, &ofpacts);
@@ -1654,7 +1635,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
 
         put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
 
-        ofctrl_add_flow(flow_table, OFTABLE_PHY_TO_LOG, 100, 0, &match,
+        ofctrl_add_flow(p_ctx->flow_table, OFTABLE_PHY_TO_LOG, 100, 0, &match,
                         &ofpacts, hc_uuid);
     }
 
@@ -1668,7 +1649,8 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
             continue;
         }
 
-        SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) {
+        SBREC_PORT_BINDING_TABLE_FOR_EACH (binding,
+                                           p_ctx->port_binding_table) {
             struct match match = MATCH_CATCHALL_INITIALIZER;
 
             if (!binding->chassis ||
@@ -1688,7 +1670,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
             put_load(1, MFF_LOG_FLAGS, MLF_RCV_FROM_VXLAN_BIT, 1, &ofpacts);
             put_resubmit(OFTABLE_LOG_INGRESS_PIPELINE, &ofpacts);
 
-            ofctrl_add_flow(flow_table, OFTABLE_PHY_TO_LOG, 100,
+            ofctrl_add_flow(p_ctx->flow_table, OFTABLE_PHY_TO_LOG, 100,
                             binding->header_.uuid.parts[0],
                             &match, &ofpacts, hc_uuid);
         }
@@ -1710,7 +1692,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     /* Resubmit to table 33. */
     ofpbuf_clear(&ofpacts);
     put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
-    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
+    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
                     &match, &ofpacts, hc_uuid);
 
     /* Table 32, priority 150.
@@ -1724,7 +1706,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     /* Resubmit to table 33. */
     ofpbuf_clear(&ofpacts);
     put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
-    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
+    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 150, 0,
                     &match, &ofpacts, hc_uuid);
 
     /* Table 32, priority 150.
@@ -1738,16 +1720,16 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     ofpbuf_clear(&ofpacts);
     put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
     const char *localport;
-    SSET_FOR_EACH (localport, local_lports) {
+    SSET_FOR_EACH (localport, p_ctx->local_lports) {
         /* Iterate over all local logical ports and insert a drop
          * rule with higher priority for every localport in this
          * datapath. */
         const struct sbrec_port_binding *pb = lport_lookup_by_name(
-            sbrec_port_binding_by_name, localport);
+            p_ctx->sbrec_port_binding_by_name, localport);
         if (pb && !strcmp(pb->type, "localport")) {
             match_set_reg(&match, MFF_LOG_INPORT - MFF_REG0, pb->tunnel_key);
             match_set_metadata(&match, htonll(pb->datapath->tunnel_key));
-            ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 150,
+            ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 150,
                             pb->header_.uuid.parts[0],
                             &match, &ofpacts, hc_uuid);
         }
@@ -1761,8 +1743,8 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     match_init_catchall(&match);
     ofpbuf_clear(&ofpacts);
     put_resubmit(OFTABLE_LOCAL_OUTPUT, &ofpacts);
-    ofctrl_add_flow(flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0, &match, &ofpacts,
-                    hc_uuid);
+    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_REMOTE_OUTPUT, 0, 0, &match,
+                    &ofpacts, hc_uuid);
 
     /* Table 34, Priority 0.
      * =======================
@@ -1776,7 +1758,7 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
         put_load(0, MFF_REG0 + i, 0, 32, &ofpacts);
     }
     put_resubmit(OFTABLE_LOG_EGRESS_PIPELINE, &ofpacts);
-    ofctrl_add_flow(flow_table, OFTABLE_CHECK_LOOPBACK, 0, 0, &match,
+    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_CHECK_LOOPBACK, 0, 0, &match,
                     &ofpacts, hc_uuid);
 
     /* Table 64, Priority 0.
@@ -1787,8 +1769,8 @@  physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
     match_init_catchall(&match);
     ofpbuf_clear(&ofpacts);
     put_resubmit(OFTABLE_LOG_TO_PHY, &ofpacts);
-    ofctrl_add_flow(flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match, &ofpacts,
-                    hc_uuid);
+    ofctrl_add_flow(p_ctx->flow_table, OFTABLE_SAVE_INPORT, 0, 0, &match,
+                    &ofpacts, hc_uuid);
 
     ofpbuf_uninit(&ofpacts);
 
diff --git a/controller/physical.h b/controller/physical.h
index c93f6b1c0..477a1cbad 100644
--- a/controller/physical.h
+++ b/controller/physical.h
@@ -42,34 +42,24 @@  struct sset;
 #define OVN_GENEVE_TYPE 0x80     /* Critical option. */
 #define OVN_GENEVE_LEN 4
 
+struct physical_ctx {
+    struct ovsdb_idl_index *sbrec_port_binding_by_name;
+    const struct sbrec_port_binding_table *port_binding_table;
+    const struct sbrec_multicast_group_table *mc_group_table;
+    const struct ovsrec_bridge *br_int;
+    const struct sbrec_chassis_table *chassis_table;
+    const struct sbrec_chassis *chassis;
+    struct ovn_desired_flow_table *flow_table;
+    const struct sset *active_tunnels;
+    struct hmap *local_datapaths;
+    struct sset *local_lports;
+    const struct simap *ct_zones;
+    enum mf_field_id mff_ovn_geneve;
+};
+
 void physical_register_ovs_idl(struct ovsdb_idl *);
-void physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
-                  const struct sbrec_multicast_group_table *,
-                  const struct sbrec_port_binding_table *,
-                  const struct sbrec_chassis_table *chassis_table,
-                  enum mf_field_id mff_ovn_geneve,
-                  const struct ovsrec_bridge *br_int,
-                  const struct sbrec_chassis *chassis,
-                  const struct simap *ct_zones,
-                  const struct hmap *local_datapaths,
-                  const struct sset *local_lports,
-                  const struct sset *active_tunnels,
-                  struct ovn_desired_flow_table *);
-void physical_handle_port_binding_changes(
-        struct ovsdb_idl_index *sbrec_port_binding_by_name,
-        const struct sbrec_port_binding_table *,
-        enum mf_field_id mff_ovn_geneve,
-        const struct sbrec_chassis *,
-        const struct simap *ct_zones,
-        struct hmap *local_datapaths,
-        struct sset *active_tunnels,
-        struct ovn_desired_flow_table *);
+void physical_run(struct physical_ctx *);
+void physical_handle_port_binding_changes(struct physical_ctx *);
 
-void physical_handle_mc_group_changes(
-        const struct sbrec_multicast_group_table *,
-        enum mf_field_id mff_ovn_geneve,
-        const struct sbrec_chassis *,
-        const struct simap *ct_zones,
-        const struct hmap *local_datapaths,
-        struct ovn_desired_flow_table *);
+void physical_handle_mc_group_changes(struct physical_ctx *);
 #endif /* controller/physical.h */