OpenSDN source code
mac_learning_proto_handler.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3
*/
4
#include "
mac_learning_init.h
"
5
#include "
mac_learning_proto.h
"
6
#include "
mac_learning_proto_handler.h
"
7
8
MacLearningProtoHandler::MacLearningProtoHandler
(
Agent
*agent,
9
boost::shared_ptr<PktInfo> info,
10
boost::asio::io_context &
io
):
11
ProtoHandler
(agent, info,
io
), intf_(NULL), vrf_(NULL), table_(NULL),
12
entry_() {
13
}
14
15
void
MacLearningProtoHandler::Log
(std::string msg) {
16
17
std::string vrf =
""
;
18
std::string intf =
""
;
19
if
(
vrf_
!= NULL) {
20
vrf =
vrf_
->
GetName
();
21
}
22
23
if
(
intf_
!= NULL) {
24
intf =
intf_
->
name
();
25
}
26
27
MAC_LEARNING_TRACE(
MacLearningTraceBuf
, vrf,
pkt_info_
->smac.ToString(), intf, msg);
28
}
29
30
void
MacLearningProtoHandler::IngressPktHandler
() {
31
const
VmInterface
*vm_intf =
dynamic_cast<
const
VmInterface
*
>
(
intf_
);
32
if
(vm_intf == NULL) {
33
Log
(
"Ingress packet on non-VMI interface"
);
34
return
;
35
}
36
37
entry_
.reset(
new
MacLearningEntryLocal
(
table_
,
pkt_info_
->agent_hdr.vrf,
38
pkt_info_
->smac,
39
pkt_info_
->agent_hdr.cmd_param,
40
intf_
));
41
}
42
43
void
MacLearningProtoHandler::EgressPktHandler
() {
44
const
PhysicalInterface
*p_intf =
45
dynamic_cast<
const
PhysicalInterface
*
>
(
intf_
);
46
if
(p_intf == NULL) {
47
Log
(
"Invalid packet on physical interface"
);
48
return
;
49
}
50
51
if
(
pkt_info_
->pbb_header == NULL) {
52
Log
(
"Non PBB packet on physical interface"
);
53
return
;
54
}
55
56
std::string bmac_vrf =
Agent::NullString
();
57
if
(
vrf_
->
vn
() &&
vrf_
->
vn
()->
GetVrf
()) {
58
bmac_vrf =
vrf_
->
vn
()->
GetVrf
()->
GetName
();
59
}
60
61
entry_
.reset(
new
MacLearningEntryPBB
(
table_
,
pkt_info_
->agent_hdr.vrf,
62
pkt_info_
->smac,
63
pkt_info_
->agent_hdr.cmd_param,
64
pkt_info_
->b_smac));
65
}
66
67
bool
MacLearningProtoHandler::Run
() {
68
intf_
=
agent
()->
interface_table
()->
69
FindInterface(
pkt_info_
->agent_hdr.ifindex);
70
if
(
intf_
== NULL) {
71
Log
(
"Invalid interface"
);
72
return
true
;
73
}
74
75
vrf_
=
agent
()->
vrf_table
()->
FindVrfFromId
(
pkt_info_
->agent_hdr.vrf);
76
if
(
vrf_
== NULL) {
77
Log
(
"Invalid VRF"
);
78
return
true
;
79
}
80
81
uint32_t table_index =
agent
()->
mac_learning_proto
()->
Hash
(
82
pkt_info_
->agent_hdr.vrf,
pkt_info_
->smac);
83
table_
=
agent
()->
mac_learning_proto
()->
Find
(table_index);
84
if
(
table_
== NULL) {
85
Log
(
"Mac learning table not found"
);
86
return
true
;
87
}
88
89
if
(
intf_
->
type
() ==
Interface::PHYSICAL
) {
90
EgressPktHandler
();
91
}
else
{
92
IngressPktHandler
();
93
}
94
95
if
(
entry_
.get()) {
96
table_
->
Add
(
entry_
);
97
Log
(
"Mac entry added"
);
98
}
99
100
return
true
;
101
}
Agent
Definition:
agent.h:360
Agent::interface_table
InterfaceTable * interface_table() const
Definition:
agent.h:467
Agent::mac_learning_proto
MacLearningProto * mac_learning_proto() const
Definition:
agent.h:1007
Agent::vrf_table
VrfTable * vrf_table() const
Definition:
agent.h:487
Agent::NullString
static const std::string & NullString()
Definition:
agent.h:439
Interface::PHYSICAL
@ PHYSICAL
Definition:
interface.h:29
Interface::name
const std::string & name() const
Definition:
interface.h:114
Interface::type
Type type() const
Definition:
interface.h:112
MacLearningEntryLocal
Definition:
mac_learning.h:145
MacLearningEntryPBB
Definition:
mac_learning.h:184
MacLearningPartition::Add
void Add(MacLearningEntryPtr ptr)
Definition:
mac_learning.cc:215
MacLearningProtoHandler::Run
bool Run()
Definition:
mac_learning_proto_handler.cc:67
MacLearningProtoHandler::IngressPktHandler
void IngressPktHandler()
Definition:
mac_learning_proto_handler.cc:30
MacLearningProtoHandler::intf_
const Interface * intf_
Definition:
mac_learning_proto_handler.h:27
MacLearningProtoHandler::vrf_
const VrfEntry * vrf_
Definition:
mac_learning_proto_handler.h:28
MacLearningProtoHandler::table_
MacLearningPartition * table_
Definition:
mac_learning_proto_handler.h:29
MacLearningProtoHandler::MacLearningProtoHandler
MacLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition:
mac_learning_proto_handler.cc:8
MacLearningProtoHandler::EgressPktHandler
void EgressPktHandler()
Definition:
mac_learning_proto_handler.cc:43
MacLearningProtoHandler::Log
void Log(std::string str)
Definition:
mac_learning_proto_handler.cc:15
MacLearningProtoHandler::entry_
MacLearningEntryPtr entry_
Definition:
mac_learning_proto_handler.h:30
MacLearningProto::Find
MacLearningPartition * Find(uint32_t index)
Definition:
mac_learning_proto.cc:81
MacLearningProto::Hash
uint32_t Hash(uint32_t vrf_id, const MacAddress &mac)
Definition:
mac_learning_proto.cc:33
PhysicalInterface
Definition:
physical_interface.h:16
ProtoHandler
Definition:
proto_handler.h:28
ProtoHandler::agent
Agent * agent() const
Definition:
proto_handler.h:80
ProtoHandler::pkt_info_
boost::shared_ptr< PktInfo > pkt_info_
Definition:
proto_handler.h:92
VmInterface
Definition:
vm_interface.h:358
VnEntry::GetVrf
VrfEntry * GetVrf() const
Definition:
vn.h:170
VrfEntry::GetName
const string & GetName() const
Definition:
vrf.h:100
VrfEntry::vn
VnEntry * vn() const
Definition:
vrf.h:101
VrfTable::FindVrfFromId
VrfEntry * FindVrfFromId(size_t index)
Definition:
vrf.cc:884
mac_learning_init.h
MacLearningTraceBuf
SandeshTraceBufferPtr MacLearningTraceBuf
mac_learning_proto.h
mac_learning_proto_handler.h
io
Definition:
io_utils.cc:11
contrail
controller
src
vnsw
agent
mac_learning
mac_learning_proto_handler.cc
Generated by
1.9.1