Skip to content

Commit

Permalink
ovn-northd-ddlog: Intern nb::Logical_Router_Port.
Browse files Browse the repository at this point in the history
Use the `--intern-table` switch to intern `Logical_Router_Port` records,
so that they can be copied and compared efficiently by pointer.

Signed-off-by: Leonid Ryzhyk <lryzhyk@vmware.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
ryzhyk authored and blp committed Apr 1, 2021
1 parent 4d9360f commit 6b643c6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion northd/helpers.dl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ relation SwitchRouterPeer(lsp: uuid, lsp_name: string, lrp: uuid)
SwitchRouterPeer(lsp, lsp_name, lrp) :-
nb::Logical_Switch_Port(._uuid = lsp, .name = lsp_name, .__type = "router", .options = options),
Some{var router_port} = options.get("router-port"),
nb::Logical_Router_Port(.name = router_port, ._uuid = lrp).
&nb::Logical_Router_Port(.name = router_port, ._uuid = lrp).

function get_bool_def(m: Map<string, string>, k: string, def: bool): bool = {
m.get(k)
Expand Down
50 changes: 25 additions & 25 deletions northd/lrouter.dl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import helpers
import lswitch

function is_enabled(lr: nb::Logical_Router): bool { is_enabled(lr.enabled) }
function is_enabled(lrp: nb::Logical_Router_Port): bool { is_enabled(lrp.enabled) }
function is_enabled(lrp: Intern<nb::Logical_Router_Port>): bool { is_enabled(lrp.enabled) }
function is_enabled(rp: RouterPort): bool { rp.lrp.is_enabled() }
function is_enabled(rp: Intern<RouterPort>): bool { rp.lrp.is_enabled() }

Expand All @@ -42,7 +42,7 @@ Warning[message] :-
LogicalRouterPortCandidate(lrp_uuid, lr_uuid),
var lrs = lr_uuid.group_by(lrp_uuid).to_set(),
lrs.size() > 1,
lrp in nb::Logical_Router_Port(._uuid = lrp_uuid),
lrp in &nb::Logical_Router_Port(._uuid = lrp_uuid),
var message = "Bad configuration: logical router port ${lrp.name} belongs "
"to more than one logical router".

Expand All @@ -69,9 +69,9 @@ LogicalRouterPort(lrp_uuid, lr_uuid) :-
relation PeerLogicalRouter(a: uuid, b: uuid)
PeerLogicalRouter(lrp_uuid, peer._uuid) :-
LogicalRouterPort(lrp_uuid, _),
lrp in nb::Logical_Router_Port(._uuid = lrp_uuid),
lrp in &nb::Logical_Router_Port(._uuid = lrp_uuid),
Some{var peer_name} = lrp.peer,
peer in nb::Logical_Router_Port(.name = peer_name),
peer in &nb::Logical_Router_Port(.name = peer_name),
peer.peer == Some{lrp.name}, // 'peer' must point back to 'lrp'
lrp_uuid != peer._uuid. // No reflexive pointers.

Expand All @@ -86,7 +86,7 @@ PeerLogicalRouter(lrp_uuid, peer._uuid) :-
relation FirstHopLogicalRouter(lrouter: uuid, lswitch: uuid)
FirstHopLogicalRouter(lrouter, lswitch) :-
LogicalRouterPort(lrp_uuid, lrouter),
lrp in nb::Logical_Router_Port(._uuid = lrp_uuid, .peer = None),
lrp in &nb::Logical_Router_Port(._uuid = lrp_uuid, .peer = None),
LogicalSwitchRouterPort(lsp_uuid, lrp.name, lswitch).

relation LogicalSwitchRouterPort(lsp: uuid, lsp_router_port: string, ls: uuid)
Expand Down Expand Up @@ -119,15 +119,15 @@ ReachableLogicalRouter(a, a) :- ReachableLogicalRouter(a, _).

// ha_chassis_group and gateway_chassis may not both be present.
Warning[message] :-
lrp in nb::Logical_Router_Port(),
lrp in &nb::Logical_Router_Port(),
lrp.ha_chassis_group.is_some(),
not lrp.gateway_chassis.is_empty(),
var message = "Both ha_chassis_group and gateway_chassis configured on "
"port ${lrp.name}; ignoring the latter".

// A distributed gateway port cannot also be an L3 gateway router.
Warning[message] :-
lrp in nb::Logical_Router_Port(),
lrp in &nb::Logical_Router_Port(),
lrp.ha_chassis_group.is_some() or not lrp.gateway_chassis.is_empty(),
lrp.options.contains_key("chassis"),
var message = "Bad configuration: distributed gateway port configured on "
Expand All @@ -143,7 +143,7 @@ relation DistributedGatewayPortCandidate(lr_uuid: uuid, lrp_uuid: uuid)
DistributedGatewayPortCandidate(lr_uuid, lrp_uuid) :-
lr in nb::Logical_Router(._uuid = lr_uuid),
LogicalRouterPort(lrp_uuid, lr._uuid),
lrp in nb::Logical_Router_Port(._uuid = lrp_uuid),
lrp in &nb::Logical_Router_Port(._uuid = lrp_uuid),
not lrp.options.contains_key("chassis"),
var has_hcg = lrp.ha_chassis_group.is_some(),
var has_gc = not lrp.gateway_chassis.is_empty(),
Expand All @@ -161,13 +161,13 @@ Warning[message] :-
* Each row means 'lrp' is the distributed gateway port on 'lr_uuid'.
*
* There is at most one distributed gateway port per logical router. */
relation DistributedGatewayPort(lrp: nb::Logical_Router_Port, lr_uuid: uuid)
relation DistributedGatewayPort(lrp: Intern<nb::Logical_Router_Port>, lr_uuid: uuid)
DistributedGatewayPort(lrp, lr_uuid) :-
DistributedGatewayPortCandidate(lr_uuid, lrp_uuid),
var lrps = lrp_uuid.group_by(lr_uuid).to_set(),
lrps.size() == 1,
Some{var lrp_uuid} = lrps.nth(0),
lrp in nb::Logical_Router_Port(._uuid = lrp_uuid).
lrp in &nb::Logical_Router_Port(._uuid = lrp_uuid).

/* HAChassis is an abstraction over nb::Gateway_Chassis and nb::HA_Chassis, which
* are different ways to represent the same configuration. Each row is
Expand Down Expand Up @@ -249,12 +249,12 @@ LogicalRouterHAChassisGroup(lr_uuid,

/* For each router port, tracks whether it's a redirect port of its router */
relation RouterPortIsRedirect(lrp: uuid, is_redirect: bool)
RouterPortIsRedirect(lrp, true) :- DistributedGatewayPort(nb::Logical_Router_Port{._uuid = lrp}, _).
RouterPortIsRedirect(lrp, true) :- DistributedGatewayPort(&nb::Logical_Router_Port{._uuid = lrp}, _).
RouterPortIsRedirect(lrp, false) :-
nb::Logical_Router_Port(._uuid = lrp),
not DistributedGatewayPort(nb::Logical_Router_Port{._uuid = lrp}, _).
&nb::Logical_Router_Port(._uuid = lrp),
not DistributedGatewayPort(&nb::Logical_Router_Port{._uuid = lrp}, _).

relation LogicalRouterRedirectPort(lr: uuid, has_redirect_port: Option<nb::Logical_Router_Port>)
relation LogicalRouterRedirectPort(lr: uuid, has_redirect_port: Option<Intern<nb::Logical_Router_Port>>)

LogicalRouterRedirectPort(lr, Some{lrp}) :-
DistributedGatewayPort(lrp, lr).
Expand Down Expand Up @@ -443,7 +443,7 @@ typedef Router = Router {
external_ids: Map<string,string>,

/* Additional computed fields. */
l3dgw_port: Option<nb::Logical_Router_Port>,
l3dgw_port: Option<Intern<nb::Logical_Router_Port>>,
redirect_port_name: string,
is_gateway: bool,
nats: Vec<NAT>,
Expand Down Expand Up @@ -513,9 +513,9 @@ RouterLBVIP(router, lb, vip, backends) :-
relation RouterRouterPeer(rport1: uuid, rport2: uuid, rport2_name: string)

RouterRouterPeer(rport1, rport2, peer_name) :-
nb::Logical_Router_Port(._uuid = rport1, .peer = peer),
&nb::Logical_Router_Port(._uuid = rport1, .peer = peer),
Some{var peer_name} = peer,
nb::Logical_Router_Port(._uuid = rport2, .name = peer_name).
&nb::Logical_Router_Port(._uuid = rport2, .name = peer_name).

/* Router port can peer with anothe router port, a switch port or have
* no peer.
Expand All @@ -542,7 +542,7 @@ RouterPortPeer(rport1, PeerRouter{rport2, rport2_name}) :-
RouterRouterPeer(rport1, rport2, rport2_name).

RouterPortPeer(rport, PeerNone) :-
nb::Logical_Router_Port(._uuid = rport),
&nb::Logical_Router_Port(._uuid = rport),
not SwitchRouterPeer(_, _, rport),
not RouterRouterPeer(rport, _, _).

Expand All @@ -553,7 +553,7 @@ RouterPortPeer(rport, PeerNone) :-
* faster convergence.) */
relation RouterPortSbOptions(lrp_uuid: uuid, options: Map<string,string>)
RouterPortSbOptions(lrp._uuid, options) :-
lrp in nb::Logical_Router_Port(),
lrp in &nb::Logical_Router_Port(),
pb in sb::Port_Binding(._uuid = lrp._uuid),
var options = {
var options = pb.options;
Expand All @@ -562,21 +562,21 @@ RouterPortSbOptions(lrp._uuid, options) :-
options
}.
RouterPortSbOptions(lrp._uuid, map_empty()) :-
lrp in nb::Logical_Router_Port(),
lrp in &nb::Logical_Router_Port(),
not sb::Port_Binding(._uuid = lrp._uuid).

relation RouterPortHasBfd(lrp_uuid: uuid, has_bfd: bool)
RouterPortHasBfd(lrp_uuid, true) :-
nb::Logical_Router_Port(._uuid = lrp_uuid, .name = logical_port),
&nb::Logical_Router_Port(._uuid = lrp_uuid, .name = logical_port),
nb::BFD(.logical_port = logical_port).
RouterPortHasBfd(lrp_uuid, false) :-
nb::Logical_Router_Port(._uuid = lrp_uuid, .name = logical_port),
&nb::Logical_Router_Port(._uuid = lrp_uuid, .name = logical_port),
not nb::BFD(.logical_port = logical_port).

/* FIXME: what should happen when extract_lrp_networks fails? */
/* RouterPort relation collects all attributes of a logical router port */
typedef RouterPort = RouterPort {
lrp: nb::Logical_Router_Port,
lrp: Intern<nb::Logical_Router_Port>,
json_name: string,
networks: lport_addresses,
router: Intern<Router>,
Expand All @@ -600,7 +600,7 @@ RouterPort[RouterPort{
.sb_options = sb_options,
.has_bfd = has_bfd
}.intern()] :-
nb::Logical_Router_Port[lrp],
lrp in &nb::Logical_Router_Port(),
Some{var networks} = extract_lrp_networks(lrp.mac, lrp.networks),
LogicalRouterPort(lrp._uuid, lrouter_uuid),
router in &Router(._uuid = lrouter_uuid),
Expand Down Expand Up @@ -765,7 +765,7 @@ RouterStaticRoute(router, key, dsts) :-
.output_port = Some{oport},
.ecmp_symmetric_reply = ecmp_symmetric_reply),
/* output_port specified */
port in &RouterPort(.lrp = nb::Logical_Router_Port{.name = oport},
port in &RouterPort(.lrp = &nb::Logical_Router_Port{.name = oport},
.networks = networks),
Some{var src_ip} = match (find_lrp_member_ip(networks, nexthop)) {
Some{src_ip} -> Some{src_ip},
Expand Down
2 changes: 1 addition & 1 deletion northd/lswitch.dl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ relation SwitchRouterPeerRef(lsp: uuid, rport: Option<Intern<RouterPort>>)

SwitchRouterPeerRef(lsp, Some{rport}) :-
SwitchRouterPeer(lsp, _, lrp),
rport in &RouterPort(.lrp = nb::Logical_Router_Port{._uuid = lrp}).
rport in &RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = lrp}).

SwitchRouterPeerRef(lsp, None) :-
nb::Logical_Switch_Port(._uuid = lsp),
Expand Down
2 changes: 1 addition & 1 deletion northd/multicast.dl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ McastPortCfg[McastPortCfg{lsp_uuid, false, flood, flood_reports}.intern()] :-
var flood_reports = options.get_bool_def("mcast_flood_reports", false).

McastPortCfg[McastPortCfg{lrp_uuid, true, flood, flood}.intern()] :-
nb::Logical_Router_Port(._uuid = lrp_uuid, .options = options),
&nb::Logical_Router_Port(._uuid = lrp_uuid, .options = options),
var flood = options.get_bool_def("mcast_flood", false).

/* Mapping between Switch and the set of router port uuids on which to flood
Expand Down
1 change: 1 addition & 0 deletions northd/ovn-nb.dlopts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
--intern-table Meter
--intern-table NAT
--intern-table Address_Set
--intern-table Logical_Router_Port
34 changes: 17 additions & 17 deletions northd/ovn_northd.dl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ relation RouterPortRAOptionsComplete(lrp: uuid, options: Map<string, string>)
RouterPortRAOptionsComplete(lrp, options) :-
RouterPortRAOptions(lrp, options).
RouterPortRAOptionsComplete(lrp, map_empty()) :-
nb::Logical_Router_Port(._uuid = lrp),
&nb::Logical_Router_Port(._uuid = lrp),
not RouterPortRAOptions(lrp, _).


Expand Down Expand Up @@ -1375,7 +1375,7 @@ nb::Out_Logical_Switch_Port(._uuid = lsp._uuid,

relation LRPIPv6Prefix0(lrp_uuid: uuid, ipv6_prefix: string)
LRPIPv6Prefix0(lrp._uuid, ipv6_prefix) :-
lrp in nb::Logical_Router_Port(),
lrp in &nb::Logical_Router_Port(),
lrp.options.get_bool_def("prefix", false),
sb::Port_Binding(.logical_port = lrp.name, .options = options),
Some{var ipv6_ra_pd_list} = options.get("ipv6_ra_pd_list"),
Expand All @@ -1386,12 +1386,12 @@ relation LRPIPv6Prefix(lrp_uuid: uuid, ipv6_prefix: Option<string>)
LRPIPv6Prefix(lrp_uuid, Some{ipv6_prefix}) :-
LRPIPv6Prefix0(lrp_uuid, ipv6_prefix).
LRPIPv6Prefix(lrp_uuid, None) :-
nb::Logical_Router_Port(._uuid = lrp_uuid),
&nb::Logical_Router_Port(._uuid = lrp_uuid),
not LRPIPv6Prefix0(lrp_uuid, _).

nb::Out_Logical_Router_Port(._uuid = _uuid,
.ipv6_prefix = to_set(ipv6_prefix)) :-
nb::Logical_Router_Port(._uuid = _uuid, .name = name),
&nb::Logical_Router_Port(._uuid = _uuid, .name = name),
LRPIPv6Prefix(_uuid, ipv6_prefix).

typedef Pipeline = Ingress | Egress
Expand Down Expand Up @@ -4797,7 +4797,7 @@ AddChassisResidentCheck(lrp, add_check) :-
AddChassisResidentCheck_(lrp, add_check).

AddChassisResidentCheck(lrp, false) :-
nb::Logical_Router_Port(._uuid = lrp),
&nb::Logical_Router_Port(._uuid = lrp),
not AddChassisResidentCheck_(lrp, _).


Expand Down Expand Up @@ -4890,7 +4890,7 @@ LogicalRouterPortNatArpNdFlow(router, nat, l3dgw_port) :-
/* Respond to ARP/NS requests on the chassis that binds the gw
* port. Drop the ARP/NS requests on other chassis.
*/
relation LogicalRouterPortNatArpNdFlow(router: Intern<Router>, nat: NAT, lrp: nb::Logical_Router_Port)
relation LogicalRouterPortNatArpNdFlow(router: Intern<Router>, nat: NAT, lrp: Intern<nb::Logical_Router_Port>)
LogicalRouterArpNdFlow(router, nat, Some{lrp}, mac, Some{extra_match}, false, 92),
LogicalRouterArpNdFlow(router, nat, Some{lrp}, mac, None, true, 91) :-
LogicalRouterPortNatArpNdFlow(router, nat, lrp),
Expand Down Expand Up @@ -4923,7 +4923,7 @@ LogicalRouterArpNdFlow(router, nat, Some{lrp}, mac, None, true, 91) :-
relation LogicalRouterArpNdFlow(
router: Intern<Router>,
nat: NAT,
lrp: Option<nb::Logical_Router_Port>,
lrp: Option<Intern<nb::Logical_Router_Port>>,
mac: string,
extra_match: Option<string>,
drop: bool,
Expand All @@ -4939,7 +4939,7 @@ LogicalRouterNdFlow(router, lrp, "nd_na", ipv6, true, mac, extra_match, drop, pr

relation LogicalRouterArpFlow(
lr: Intern<Router>,
lrp: Option<nb::Logical_Router_Port>,
lrp: Option<Intern<nb::Logical_Router_Port>>,
ip: in_addr,
mac: string,
extra_match: Option<string>,
Expand Down Expand Up @@ -4982,7 +4982,7 @@ Flow(.logical_datapath = lr._uuid,

relation LogicalRouterNdFlow(
lr: Intern<Router>,
lrp: Option<nb::Logical_Router_Port>,
lrp: Option<Intern<nb::Logical_Router_Port>>,
action: string,
ip: in6_addr,
sn_ip: bool,
Expand Down Expand Up @@ -5118,7 +5118,7 @@ Flow(.logical_datapath = lr_uuid,
.__match = "ip4.dst == {" ++ match_ips.join(", ") ++ "}",
.actions = "drop;",
.external_ids = stage_hint(lrp_uuid)) :-
&RouterPort(.lrp = nb::Logical_Router_Port{._uuid = lrp_uuid},
&RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = lrp_uuid},
.router = &Router{.snat_ips = snat_ips,
.force_lb_snat = false,
._uuid = lr_uuid},
Expand All @@ -5132,7 +5132,7 @@ Flow(.logical_datapath = lr_uuid,
.__match = "ip6.dst == {" ++ match_ips.join(", ") ++ "}",
.actions = "drop;",
.external_ids = stage_hint(lrp_uuid)) :-
&RouterPort(.lrp = nb::Logical_Router_Port{._uuid = lrp_uuid},
&RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = lrp_uuid},
.router = &Router{.snat_ips = snat_ips,
.force_lb_snat = false,
._uuid = lr_uuid},
Expand Down Expand Up @@ -6218,7 +6218,7 @@ function copy_ra_to_sb(port: RouterPort, address_mode: string): Map<string, stri
/* Logical router ingress table ND_RA_OPTIONS and ND_RA_RESPONSE: IPv6 Router
* Adv (RA) options and response. */
// FIXME: do these rules apply to derived ports?
for (&RouterPort[port@RouterPort{.lrp = lrp@nb::Logical_Router_Port{.peer = None},
for (&RouterPort[port@RouterPort{.lrp = lrp@&nb::Logical_Router_Port{.peer = None},
.router = router,
.json_name = json_name,
.networks = networks,
Expand Down Expand Up @@ -6827,7 +6827,7 @@ for (rp in &RouterPort(.peer = PeerRouter{peer_port, _},
.router = router,
.networks = networks))
{
for (&RouterPort(.lrp = nb::Logical_Router_Port{._uuid = peer_port},
for (&RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = peer_port},
.json_name = peer_json_name,
.router = peer_router))
{
Expand Down Expand Up @@ -6895,7 +6895,7 @@ Flow(.logical_datapath = lr_uuid,
.__match = "ip4.dst == {" ++ match_ips.join(", ") ++ "}",
.actions = "drop;",
.external_ids = stage_hint(lrp_uuid)) :-
&RouterPort(.lrp = nb::Logical_Router_Port{._uuid = lrp_uuid},
&RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = lrp_uuid},
.router = &Router{.snat_ips = snat_ips,
._uuid = lr_uuid},
.networks = networks),
Expand All @@ -6908,7 +6908,7 @@ Flow(.logical_datapath = lr_uuid,
.__match = "ip6.dst == {" ++ match_ips.join(", ") ++ "}",
.actions = "drop;",
.external_ids = stage_hint(lrp_uuid)) :-
&RouterPort(.lrp = nb::Logical_Router_Port{._uuid = lrp_uuid},
&RouterPort(.lrp = &nb::Logical_Router_Port{._uuid = lrp_uuid},
.router = &Router{.snat_ips = snat_ips,
._uuid = lr_uuid},
.networks = networks),
Expand Down Expand Up @@ -7636,7 +7636,7 @@ PreserveIPv6RAPDList(lrp_uuid, ipv6_ra_pd_list) :-
sb::Port_Binding(._uuid = lrp_uuid, .options = options),
var ipv6_ra_pd_list = options.get("ipv6_ra_pd_list").
PreserveIPv6RAPDList(lrp_uuid, None) :-
nb::Logical_Router_Port(._uuid = lrp_uuid),
&nb::Logical_Router_Port(._uuid = lrp_uuid),
not sb::Port_Binding(._uuid = lrp_uuid).

/*
Expand Down Expand Up @@ -7733,7 +7733,7 @@ sb::Out_IP_Multicast(._uuid = cfg.datapath,

relation PortExists(name: string)
PortExists(name) :- nb::Logical_Switch_Port(.name = name).
PortExists(name) :- nb::Logical_Router_Port(.name = name).
PortExists(name) :- &nb::Logical_Router_Port(.name = name).

sb::Out_Load_Balancer(._uuid = lb._uuid,
.name = lb.name,
Expand Down

0 comments on commit 6b643c6

Please sign in to comment.