OpenSDN source code
mac_ip_learning_proto_handler.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Juniper Networks, Inc. All rights reserved.
3
* Copyright Contributors to the OpenSDN project
4
*/
5
#include "
mac_learning_init.h
"
6
#include "
mac_learning_proto.h
"
7
#include "
mac_ip_learning_proto_handler.h
"
8
9
MacIpLearningProtoHandler::MacIpLearningProtoHandler
(
Agent
*agent,
10
boost::shared_ptr<PktInfo> info,
11
boost::asio::io_context &
io
):
12
ProtoHandler
(agent, info,
io
), intf_(NULL), vrf_(NULL), table_(NULL),
13
entry_() {
14
}
15
16
void
MacIpLearningProtoHandler::Log
(std::string msg) {
17
18
std::string vrf =
""
;
19
std::string intf =
""
;
20
if
(
vrf_
!= NULL) {
21
vrf =
vrf_
->
GetName
();
22
}
23
24
if
(
intf_
!= NULL) {
25
intf =
intf_
->
name
();
26
}
27
28
MAC_IP_LEARNING_TRACE(
MacLearningTraceBuf
, vrf,
pkt_info_
->ip_saddr.to_string(),
29
pkt_info_
->smac.ToString(), intf, msg);
30
}
31
32
bool
MacIpLearningProtoHandler::Run
() {
33
intf_
=
agent
()->
interface_table
()->
34
FindInterface(
pkt_info_
->agent_hdr.ifindex);
35
if
(
intf_
== NULL) {
36
Log
(
"Invalid interface"
);
37
return
true
;
38
}
39
40
vrf_
=
agent
()->
vrf_table
()->
FindVrfFromId
(
pkt_info_
->agent_hdr.vrf);
41
if
(
vrf_
== NULL) {
42
Log
(
"Invalid VRF"
);
43
return
true
;
44
}
45
46
const
VmInterface
*vm_intf =
dynamic_cast<
const
VmInterface
*
>
(
intf_
);
47
if
(vm_intf == NULL) {
48
Log
(
"Ingress packet on non-VMI interface"
);
49
return
true
;
50
}
51
uint32_t vrf_id = 0;
52
if
(
pkt_info_
->agent_hdr.vrf == 0) {
53
vrf_id = vm_intf->
vrf_id
();
54
}
else
{
55
vrf_id =
pkt_info_
->agent_hdr.vrf;
56
}
57
table_
=
agent
()->
mac_learning_proto
()->
GetMacIpLearningTable
();
58
entry_
.reset(
new
MacIpLearningEntry
(
table_
, vrf_id,
59
pkt_info_
->ip_saddr,
60
pkt_info_
->smac,
61
intf_
));
62
if
(
entry_
.get()) {
63
agent
()->
mac_learning_proto
()->
GetMacIpLearningTable
()->
Add
(
entry_
);
64
Log
(
"Mac entry added"
);
65
}
66
67
return
true
;
68
}
Agent
Definition:
agent.h:361
Agent::interface_table
InterfaceTable * interface_table() const
Definition:
agent.h:468
Agent::mac_learning_proto
MacLearningProto * mac_learning_proto() const
Definition:
agent.h:1008
Agent::vrf_table
VrfTable * vrf_table() const
Definition:
agent.h:488
Interface::name
const std::string & name() const
Definition:
interface.h:117
Interface::vrf_id
uint32_t vrf_id() const
Definition:
interface.cc:621
MacIpLearningEntry
Definition:
mac_ip_learning.h:20
MacIpLearningProtoHandler::table_
MacIpLearningTable * table_
Definition:
mac_ip_learning_proto_handler.h:29
MacIpLearningProtoHandler::Log
void Log(std::string str)
Definition:
mac_ip_learning_proto_handler.cc:16
MacIpLearningProtoHandler::vrf_
const VrfEntry * vrf_
Definition:
mac_ip_learning_proto_handler.h:28
MacIpLearningProtoHandler::Run
bool Run()
Definition:
mac_ip_learning_proto_handler.cc:32
MacIpLearningProtoHandler::intf_
const Interface * intf_
Definition:
mac_ip_learning_proto_handler.h:27
MacIpLearningProtoHandler::MacIpLearningProtoHandler
MacIpLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition:
mac_ip_learning_proto_handler.cc:9
MacIpLearningProtoHandler::entry_
MacLearningEntryPtr entry_
Definition:
mac_ip_learning_proto_handler.h:30
MacIpLearningTable::Add
void Add(MacLearningEntryPtr ptr)
Definition:
mac_ip_learning.cc:65
MacLearningProto::GetMacIpLearningTable
MacIpLearningTable * GetMacIpLearningTable()
Definition:
mac_learning_proto.cc:108
ProtoHandler
Definition:
proto_handler.h:29
ProtoHandler::agent
Agent * agent() const
Definition:
proto_handler.h:81
ProtoHandler::pkt_info_
boost::shared_ptr< PktInfo > pkt_info_
Definition:
proto_handler.h:93
VmInterface
Definition:
vm_interface.h:361
VrfEntry::GetName
const string & GetName() const
Definition:
vrf.h:104
VrfTable::FindVrfFromId
VrfEntry * FindVrfFromId(size_t index)
Definition:
vrf.cc:885
mac_ip_learning_proto_handler.h
mac_learning_init.h
MacLearningTraceBuf
SandeshTraceBufferPtr MacLearningTraceBuf
mac_learning_proto.h
io
Definition:
io_utils.cc:12
contrail
controller
src
vnsw
agent
mac_learning
mac_ip_learning_proto_handler.cc
Generated by
1.9.1