Skip to content

Commit

Permalink
Merge "Logic to identify the nature of label in fmd"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Dec 15, 2015
2 parents 42f3362 + bcbbf1c commit 4ee746e
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 20 deletions.
3 changes: 2 additions & 1 deletion dp-core/vr_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ vr_bridge_input(struct vrouter *router, struct vr_packet *pkt,
vr_init_forwarding_md(&cmd);
fmd = &cmd;
}
fmd->fmd_label = rt.rtr_req.rtr_label;
vr_forwarding_md_set_label(fmd, rt.rtr_req.rtr_label,
VR_LABEL_TYPE_UNKNOWN);
}

nh_output(pkt, nh, fmd);
Expand Down
18 changes: 11 additions & 7 deletions dp-core/vr_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,14 @@ vr_flow_fill_pnode(struct vr_packet_node *pnode, struct vr_packet *pkt,
* returns a different nexthop, in which case the ecmp index will return
* a bad nexthop. to avoid that, we will cache the label, and reuse it
*/
if (pkt->vp_nh &&
(pkt->vp_nh->nh_type == NH_VRF_TRANSLATE) &&
(pkt->vp_nh->nh_flags & NH_FLAG_VNID))
pnode->pl_flags |= PN_FLAG_LABEL_IS_VNID;

pkt->vp_nh = NULL;

pnode->pl_vif_idx = pkt->vp_if->vif_idx;
if (fmd) {
pnode->pl_outer_src_ip = fmd->fmd_outer_src_ip;
pnode->pl_label = fmd->fmd_label;
if (vr_forwarding_md_label_is_vxlan_id(fmd))
pnode->pl_flags |= PN_FLAG_LABEL_IS_VXLAN_ID;
if (fmd->fmd_to_me)
pnode->pl_flags |= PN_FLAG_TO_ME;
}
Expand Down Expand Up @@ -1267,7 +1264,14 @@ vr_flow_flush_pnode(struct vrouter *router, struct vr_packet_node *pnode,
flow_result_t result;

fmd->fmd_outer_src_ip = pnode->pl_outer_src_ip;
fmd->fmd_label = pnode->pl_label;
if (pnode->pl_flags & PN_FLAG_LABEL_IS_VXLAN_ID) {
vr_forwarding_md_set_label(fmd, pnode->pl_label,
VR_LABEL_TYPE_VXLAN_ID);
} else {
vr_forwarding_md_set_label(fmd, pnode->pl_label,
VR_LABEL_TYPE_MPLS);
}

if (pnode->pl_flags & PN_FLAG_TO_ME)
fmd->fmd_to_me = 1;

Expand All @@ -1290,7 +1294,7 @@ vr_flow_flush_pnode(struct vrouter *router, struct vr_packet_node *pnode,
if (!pkt->vp_nh) {
if (vif_is_fabric(pkt->vp_if) && fmd &&
(fmd->fmd_label >= 0)) {
if (!(pnode->pl_flags & PN_FLAG_LABEL_IS_VNID))
if (!vr_forwarding_md_label_is_vxlan_id(fmd))
pkt->vp_nh = __vrouter_get_label(router, fmd->fmd_label);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ vr_mpls_input(struct vrouter *router, struct vr_packet *pkt,

ip = (struct vr_ip *)pkt_network_header(pkt);
fmd->fmd_outer_src_ip = ip->ip_saddr;
fmd->fmd_label = label;
vr_forwarding_md_set_label(fmd, label, VR_LABEL_TYPE_MPLS);

/* Store the TTL in packet. Will be used for multicast replication */
pkt->vp_ttl = ttl;
Expand Down
23 changes: 16 additions & 7 deletions dp-core/vr_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ nh_vxlan_tunnel_helper(struct vr_packet *pkt, struct vr_forwarding_md *fmd,
}
}

vr_forwarding_md_update_label_type(fmd, VR_LABEL_TYPE_VXLAN_ID);

/* Add the vxlan header */
vxlanh = (struct vr_vxlan *)pkt_push(pkt, sizeof(struct vr_vxlan));
vxlanh->vxlan_vnid = htonl(fmd->fmd_label << VR_VXLAN_VNID_SHIFT);
Expand Down Expand Up @@ -527,7 +529,9 @@ nh_composite_ecmp(struct vr_packet *pkt, struct vr_nexthop *nh,
return 0;
}

fmd->fmd_label = nh->nh_component_nh[fmd->fmd_ecmp_nh_index].cnh_label;
vr_forwarding_md_set_label(fmd,
nh->nh_component_nh[fmd->fmd_ecmp_nh_index].cnh_label,
VR_LABEL_TYPE_UNKNOWN);
return nh_output(pkt, member_nh, fmd);

drop:
Expand Down Expand Up @@ -825,14 +829,13 @@ nh_composite_mcast_l2(struct vr_packet *pkt, struct vr_nexthop *nh,

label = fmd->fmd_label;
for (i = 0; i < nh->nh_component_cnt; i++) {

clone_size = 0;
dir_nh = nh->nh_component_nh[i].cnh;

/* We need to copy back the original label from Bridge lookaup
* as previous iteration would have manipulated that
*/
fmd->fmd_label = label;
vr_forwarding_md_set_label(fmd, label, VR_LABEL_TYPE_UNKNOWN);
fmd->fmd_dvrf = pkt_vrf;

/* If direct nexthop is not valid, dont process it */
Expand Down Expand Up @@ -1010,7 +1013,8 @@ nh_composite_tor(struct vr_packet *pkt, struct vr_nexthop *nh,
break;
}

fmd->fmd_label = nh->nh_component_nh[i].cnh_label;
vr_forwarding_md_set_label(fmd, nh->nh_component_nh[i].cnh_label,
VR_LABEL_TYPE_UNKNOWN);
fmd->fmd_dvrf = dir_nh->nh_dev->vif_vrf;
nh_output(new_pkt, dir_nh, fmd);
}
Expand Down Expand Up @@ -1062,7 +1066,8 @@ nh_composite_evpn(struct vr_packet *pkt, struct vr_nexthop *nh,
break;
}

fmd->fmd_label = nh->nh_component_nh[i].cnh_label;
vr_forwarding_md_set_label(fmd, nh->nh_component_nh[i].cnh_label,
VR_LABEL_TYPE_UNKNOWN);
fmd->fmd_dvrf = dir_nh->nh_dev->vif_vrf;
nh_output(new_pkt, dir_nh, fmd);
}
Expand Down Expand Up @@ -1183,7 +1188,7 @@ nh_composite_fabric(struct vr_packet *pkt, struct vr_nexthop *nh,
* Add vxlan encapsulation. The vxlan id need to be taken
* from Bridge entry
*/
fmd->fmd_label = label;
vr_forwarding_md_set_label(fmd, label, VR_LABEL_TYPE_UNKNOWN);
fmd->fmd_dvrf = dir_nh->nh_dev->vif_vrf;
if (nh_vxlan_tunnel_helper(new_pkt, fmd, sip, sip) == false) {
vr_pfree(new_pkt, VP_DROP_PUSH);
Expand All @@ -1197,7 +1202,8 @@ nh_composite_fabric(struct vr_packet *pkt, struct vr_nexthop *nh,
}

/* MPLS label for outer header encapsulation */
fmd->fmd_label = nh->nh_component_nh[i].cnh_label;
vr_forwarding_md_set_label(fmd, nh->nh_component_nh[i].cnh_label,
VR_LABEL_TYPE_UNKNOWN);
fmd->fmd_dvrf = dir_nh->nh_dev->vif_vrf;
nh_output(new_pkt, dir_nh, fmd);
}
Expand Down Expand Up @@ -1415,6 +1421,8 @@ nh_mpls_udp_tunnel(struct vr_packet *pkt, struct vr_nexthop *nh,
if (!fmd || fmd->fmd_label < 0)
return vr_forward(nh->nh_router, pkt, fmd);

vr_forwarding_md_update_label_type(fmd, VR_LABEL_TYPE_MPLS);

if (fmd->fmd_udp_src_port)
udp_src_port = fmd->fmd_udp_src_port;

Expand Down Expand Up @@ -1549,6 +1557,7 @@ nh_gre_tunnel(struct vr_packet *pkt, struct vr_nexthop *nh,
if (!fmd || fmd->fmd_label < 0)
return vr_forward(nh->nh_router, pkt, fmd);

vr_forwarding_md_update_label_type(fmd, VR_LABEL_TYPE_MPLS);

if (vr_perfs)
pkt->vp_flags |= VP_FLAG_GSO;
Expand Down
3 changes: 2 additions & 1 deletion dp-core/vr_proto_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ vr_forward(struct vrouter *router, struct vr_packet *pkt,
vr_init_forwarding_md(&rt_fmd);
fmd = &rt_fmd;
}
fmd->fmd_label = rt.rtr_req.rtr_label;
vr_forwarding_md_set_label(fmd, rt.rtr_req.rtr_label,
VR_LABEL_TYPE_UNKNOWN);
}

vif = nh->nh_dev;
Expand Down
3 changes: 2 additions & 1 deletion dp-core/vr_vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ vr_vxlan_input(struct vrouter *router, struct vr_packet *pkt,
drop_reason = VP_DROP_PULL;
goto fail;
}
fmd->fmd_label = vnid;

vr_forwarding_md_set_label(fmd, vnid, VR_LABEL_TYPE_VXLAN_ID);

nh = (struct vr_nexthop *)vr_itable_get(router->vr_vxlan_table, vnid);
if (!nh) {
Expand Down
2 changes: 1 addition & 1 deletion include/vr_flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct vr_flow_stats {

#define VR_MAX_FLOW_QUEUE_ENTRIES 3U

#define PN_FLAG_LABEL_IS_VNID 0x1
#define PN_FLAG_LABEL_IS_VXLAN_ID 0x1
#define PN_FLAG_TO_ME 0x2

struct vr_packet_node {
Expand Down
41 changes: 41 additions & 0 deletions include/vr_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ enum {
TOR_SOURCE,
};

enum {
VR_LABEL_TYPE_UNKNOWN,
VR_LABEL_TYPE_MPLS,
VR_LABEL_TYPE_VXLAN_ID
};

/*
* forwarding metadata is something that is carried through out the
* forwarding path. we are constrained by what can be held in the
Expand All @@ -756,6 +762,8 @@ enum {
* degradation, if so used. please also watch what you are doing with
* this variable
*/
#define FMD_FLAG_LABEL_IS_VXLAN_ID 0x01

struct vr_forwarding_md {
int32_t fmd_flow_index;
int32_t fmd_label;
Expand All @@ -767,6 +775,7 @@ struct vr_forwarding_md {
uint16_t fmd_udp_src_port;
uint8_t fmd_to_me;
uint8_t fmd_src;
uint8_t fmd_flags;
};

static inline void
Expand All @@ -782,6 +791,38 @@ vr_init_forwarding_md(struct vr_forwarding_md *fmd)
fmd->fmd_udp_src_port = 0;
fmd->fmd_to_me = 0;
fmd->fmd_src = 0;
fmd->fmd_flags = 0;
return;
}

static inline bool
vr_forwarding_md_label_is_vxlan_id(struct vr_forwarding_md *fmd)
{
if (fmd->fmd_flags & FMD_FLAG_LABEL_IS_VXLAN_ID)
return true;
return false;
}

static inline void
vr_forwarding_md_update_label_type(struct vr_forwarding_md *fmd,
unsigned int type)
{
if (type == VR_LABEL_TYPE_VXLAN_ID) {
fmd->fmd_flags |= FMD_FLAG_LABEL_IS_VXLAN_ID;
} else {
fmd->fmd_flags &= ~FMD_FLAG_LABEL_IS_VXLAN_ID;
}

return;
}

static inline void
vr_forwarding_md_set_label(struct vr_forwarding_md *fmd, unsigned int label,
unsigned int type)
{
fmd->fmd_label = label;
vr_forwarding_md_update_label_type(fmd, type);

return;
}

Expand Down
2 changes: 1 addition & 1 deletion utils/rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ vr_route_req_process(void *s_req)
if (rt->rtr_label_flags & VR_BE_FLOOD_DHCP_FLAG)
strcat(flags, "Df");

ret = printf("%-8d", rt->rtr_index);
ret = printf("%-9d", rt->rtr_index);
for (i = ret; i < 12; i++)
printf(" ");

Expand Down

0 comments on commit 4ee746e

Please sign in to comment.