Skip to content

Commit

Permalink
Merge "Pick rpf nexthop for layer2 flow from layer3 route table."
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 5, 2015
2 parents dbacad9 + b032227 commit f3ae003
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 36 deletions.
6 changes: 5 additions & 1 deletion src/vnsw/agent/init/agent_init.cc
Expand Up @@ -209,6 +209,11 @@ static void CreateVrfIndependentNextHop(Agent *agent) {
(agent->nexthop_table()->FindActiveEntry(&key1));
agent->nexthop_table()->set_discard_nh(nh);

//Reserve index 2, this would be used to
//set as RPF NH when packet has to be discarded
//due to source route mismatch
assert(agent->nexthop_table()->ReserveIndex() ==
NextHopTable::kRpfDiscardIndex);
L2ReceiveNH::Create();
L2ReceiveNHKey key2;
nh = static_cast<NextHop *>
Expand Down Expand Up @@ -238,7 +243,6 @@ void AgentInit::CreateVrfBase() {
}

void AgentInit::CreateNextHopsBase() {
CreateVrfIndependentNextHop(agent_.get());
CreateNextHops();
}

Expand Down
4 changes: 4 additions & 0 deletions src/vnsw/agent/oper/nexthop.cc
Expand Up @@ -77,6 +77,10 @@ NextHopTable::~NextHopTable() {
FreeInterfaceId(0);
}

uint32_t NextHopTable::ReserveIndex() {
return index_table_.Insert(NULL);
}

void NextHop::SendObjectLog(AgentLogEvent::type event) const {
NextHopObjectLogInfo info;

Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/nexthop.h
Expand Up @@ -1358,6 +1358,7 @@ class CompositeNH : public NextHop {
/////////////////////////////////////////////////////////////////////////////
class NextHopTable : public AgentDBTable {
public:
static const uint32_t kRpfDiscardIndex = 2;
NextHopTable(DB *db, const std::string &name);
virtual ~NextHopTable();

Expand Down Expand Up @@ -1412,6 +1413,7 @@ class NextHopTable : public AgentDBTable {
// NextHop index managing routines
void FreeInterfaceId(size_t index) { index_table_.Remove(index); }
NextHop *FindNextHop(size_t index);
uint32_t ReserveIndex();

private:
NextHop *AllocWithKey(const DBRequestKey *k) const;
Expand Down
57 changes: 51 additions & 6 deletions src/vnsw/agent/pkt/flow_table.cc
Expand Up @@ -1252,7 +1252,36 @@ void FlowEntry::SetAclFlowSandeshData(const AclDBEntry *acl,
fe_sandesh_data.set_dmac(data_.dmac.ToString());
}

bool FlowEntry::SetRpfNH(const AgentRoute *rt) {
bool FlowEntry::SetRpfNH(FlowTable *ft, const AgentRoute *rt) {
bool ret = false;
//If l2 flow has a ip route entry present in
//layer 3 table, then use that for calculating
//rpf nexthop, else use layer 2 route entry(baremetal
//scenario where layer 3 route may not be present)

if (l3_flow() == false) {
//For ingress flow, agent always sets
//rpf NH from layer 3 route entry
//In case of egress flow if route entry is present
//and its a host route entry use it for RPF NH
//For baremetal case since IP address may not be known
//agent uses layer 2 route entry
InetUnicastRouteEntry *ip_rt = static_cast<InetUnicastRouteEntry *>(
ft->GetUcRoute(rt->vrf(), key().src_addr));
if (is_flags_set(FlowEntry::IngressDir) ||
(ip_rt && ip_rt->IsHostRoute())) {
rt = ip_rt;
}
}

if (!rt) {
if (data_.nh_state_ != NULL) {
data_.nh_state_ = NULL;
ret = true;
}
return ret;
}

const NextHop *nh = rt->GetActiveNextHop();
if (nh->GetType() == NextHop::COMPOSITE &&
!is_flags_set(FlowEntry::LocalFlow) &&
Expand Down Expand Up @@ -1394,7 +1423,7 @@ void FlowEntry::InitFwdFlow(const PktFlowInfo *info, const PktInfo *pkt,
reset_flags(FlowEntry::IngressDir);
}
if (ctrl->rt_ != NULL) {
SetRpfNH(ctrl->rt_);
SetRpfNH(info->flow_table, ctrl->rt_);
}

data_.flow_source_vrf = info->flow_source_vrf;
Expand Down Expand Up @@ -1449,7 +1478,7 @@ void FlowEntry::InitRevFlow(const PktFlowInfo *info, const PktInfo *pkt,
}
}
if (ctrl->rt_ != NULL) {
SetRpfNH(ctrl->rt_);
SetRpfNH(info->flow_table, ctrl->rt_);
}

data_.flow_source_vrf = info->flow_dest_vrf;
Expand Down Expand Up @@ -2077,6 +2106,10 @@ void InetRouteFlowUpdate::RouteDel(AgentRoute *entry) {
bool InetRouteFlowUpdate::SgUpdate(FlowEntry *fe, FlowTable *table,
RouteFlowKey &key,
const SecurityGroupList &sg_list) {
if (fe->l3_flow() == false) {
return true;
}

fe->GetPolicyInfo();

// Update SG-ID List
Expand Down Expand Up @@ -2178,6 +2211,9 @@ void BridgeEntryFlowUpdate::RouteDel(AgentRoute *entry) {
bool BridgeEntryFlowUpdate::SgUpdate(FlowEntry *fe, FlowTable *table,
RouteFlowKey &key,
const SecurityGroupList &sg_list) {
if (fe->l3_flow() == true) {
return true;
}
fe->GetPolicyInfo();

// Update SG-ID List
Expand Down Expand Up @@ -2395,7 +2431,7 @@ void FlowTable::ResyncRpfNH(const RouteFlowKey &key, const AgentRoute *rt) {
continue;
}

if (flow->SetRpfNH(rt) == true) {
if (flow->SetRpfNH(this, rt) == true) {
flow->UpdateKSync(this);
FlowInfo flow_info;
flow->FillFlowInfo(flow_info);
Expand All @@ -2420,6 +2456,9 @@ void FlowTable::FlowRecompute(RouteFlowInfo *rt_info) {
/* for reverse flow trigger a re-eval on its forward flow */
fe = fe->reverse_flow_entry();
}
if (fe->l3_flow() == false) {
continue;
}
if (fe->set_pending_recompute(true)) {
agent_->pkt()->pkt_handler()->SendMessage(PktHandler::FLOW,
new FlowTaskMsg(fe));
Expand Down Expand Up @@ -2681,9 +2720,10 @@ void FlowTable::DeleteL2RouteFlowInfo(FlowEntry *fe) {
}

void FlowTable::DeleteRouteFlowInfo (FlowEntry *fe) {
if (fe->l3_flow_) {
if (fe->l3_flow()) {
DeleteInetRouteFlowInfo(fe);
} else {
DeleteInetRouteFlowInfo(fe);
DeleteL2RouteFlowInfo(fe);
}
}
Expand Down Expand Up @@ -2987,9 +3027,14 @@ void FlowTable::AddL2RouteFlowInfo (FlowEntry *fe) {
}

void FlowTable::AddRouteFlowInfo (FlowEntry *fe) {
if (fe->l3_flow_) {
if (fe->l3_flow()) {
AddInetRouteFlowInfo(fe);
} else {
//For layer 2 flow, we add flow entry in both
//inet and layer 2 tree entry. This
//get s used to resync rpf nexthop for a layer2 flow
//since its calculated based on layer3 route entry
AddInetRouteFlowInfo(fe);
AddL2RouteFlowInfo(fe);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/pkt/flow_table.h
Expand Up @@ -430,7 +430,7 @@ class FlowEntry {
friend class FlowStatsCollector;
friend void intrusive_ptr_add_ref(FlowEntry *fe);
friend void intrusive_ptr_release(FlowEntry *fe);
bool SetRpfNH(const AgentRoute *rt);
bool SetRpfNH(FlowTable *ft, const AgentRoute *rt);
bool InitFlowCmn(const PktFlowInfo *info, const PktControlInfo *ctrl,
const PktControlInfo *rev_ctrl);
void GetSourceRouteInfo(const AgentRoute *rt);
Expand Down
12 changes: 6 additions & 6 deletions src/vnsw/agent/pkt/test/egress-flow.xml
Expand Up @@ -35,13 +35,13 @@
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="3"
type="flow" />
<validate name="validate-2">
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="10" sip="1.1.1.2"
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="1" svn="__UNKNOWN__"
dvn="vn1" action="drop"/>
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="14" sip="1.1.1.2"
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="2" svn="__UNKNOWN__"
dvn="vn1" action="drop"/>
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="13" sip="1.1.1.2"
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="14" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="3" svn="__UNKNOWN__"
dvn="vn1" action="drop"/>
</validate>
Expand Down Expand Up @@ -73,13 +73,13 @@
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="13"
type="flow" />
<validate name="validate-4">
<flow name="l2-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="10" sip="1.1.1.2"
<flow name="l2-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="11" svn="vn1"
dvn="vn1" action="pass"/>
<flow name="l2-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="14" sip="1.1.1.2"
<flow name="l2-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="12" svn="vn1"
dvn="vn1" action="pass"/>
<flow name="l3-udp-to-vm-1" uuid="1" vrf="vrf1" nh="13" sip="1.1.1.2"
<flow name="l3-udp-to-vm-1" uuid="1" vrf="vrf1" nh="14" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="13" svn="vn1"
dvn="vn1" action="pass"/>
</validate>
Expand Down
12 changes: 6 additions & 6 deletions src/vnsw/agent/pkt/test/ingress-flow.xml
Expand Up @@ -26,10 +26,10 @@
sip="1.1.1.1" dip="1.1.1.2" proto="udp" sport="1" dport="2"
type="flow" />
<validate name="validate-2">
<flow name="l2-udp-from-vm-1" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.1"
<flow name="l2-udp-from-vm-1" uuid="1" vrf="vrf1" nh="12" sip="1.1.1.1"
dip="1.1.1.2" proto="udp" sport="1" dport="1" svn="vn1"
dvn="__UNKNOWN__" action="drop"/>
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.1"
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="12" sip="1.1.1.1"
dip="1.1.1.2" proto="udp" sport="1" dport="2" svn="vn1"
dvn="__UNKNOWN__" action="drop"/>
</validate>
Expand All @@ -54,12 +54,12 @@
sip="1.1.1.1" dip="1.1.1.2" proto="udp" sport="1" dport="12"
type="flow" />
<validate name="validate-3">
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.1"
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="12" sip="1.1.1.1"
dip="1.1.1.2" proto="udp" sport="1" dport="11" svn="vn1"
dvn="vn1" action="pass"/>
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.1"
dvn="vn1" action="pass" rpf_nh="13"/>
<flow name="l2-udp-from-vm-2" uuid="1" vrf="vrf1" nh="12" sip="1.1.1.1"
dip="1.1.1.2" proto="udp" sport="1" dport="12" svn="vn1"
dvn="vn1" action="pass"/>
dvn="vn1" action="pass" rpf_nh="13"/>
</validate>

<virtual-machine-interface delete="1" nova="1"
Expand Down
18 changes: 9 additions & 9 deletions src/vnsw/agent/pkt/test/l2-sg-flow.xml
Expand Up @@ -55,13 +55,13 @@
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="3"
type="flow" />
<validate name="validate-2">
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="10" sip="1.1.1.2"
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="1" svn="vn1"
dvn="vn1" action="drop"/>
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="16" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="2" svn="vn1"
dvn="vn1" action="drop"/>
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="16" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="3" svn="vn1"
dvn="vn1" action="drop"/>
</validate>
Expand All @@ -70,13 +70,13 @@
vn="vn1" vxlan_id="0" tunnel-dest="5.5.5.5" tunnel-type="vxlan" sg="1"
label="5" />
<validate name="validate-3">
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="10" sip="1.1.1.2"
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="11" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="1" svn="vn1"
dvn="vn1" action="pass"/>
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="16" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="2" svn="vn1"
dvn="vn1" action="pass"/>
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="15" sip="1.1.1.2"
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="16" sip="1.1.1.2"
dip="1.1.1.1" proto="udp" sport="1" dport="3" svn="vn1"
dvn="vn1" action="pass"/>
</validate>
Expand All @@ -90,13 +90,13 @@
</acl>

<validate name="validate-4">
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="10"
<flow name="l2-vxlan-udp-to-vm-vxlan-1" uuid="1" vrf="vrf1" nh="11"
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="1" svn="vn1"
dvn="vn1" action="drop"/>
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="15"
<flow name="l2-gre-udp-to-vm-gre-1" uuid="1" vrf="vrf1" nh="16"
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="2" svn="vn1"
dvn="vn1" action="drop"/>
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="15"
<flow name="l3-gre-udp-to-vm-1" uuid="1" vrf="vrf1" nh="16"
sip="1.1.1.2" dip="1.1.1.1" proto="udp" sport="1" dport="3" svn="vn1"
dvn="vn1" action="drop"/>
</validate>
Expand Down

0 comments on commit f3ae003

Please sign in to comment.