OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
4 #include "mac_learning_init.h"
5 #include "mac_learning_proto.h"
7 
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 MacIpLearningProtoHandler::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_IP_LEARNING_TRACE(MacLearningTraceBuf, vrf, pkt_info_->ip_saddr.to_string(),
28  pkt_info_->smac.ToString(), intf, msg);
29 }
30 
32  intf_ = agent()->interface_table()->
33  FindInterface(pkt_info_->agent_hdr.ifindex);
34  if (intf_ == NULL) {
35  Log("Invalid interface");
36  return true;
37  }
38 
39  vrf_ = agent()->vrf_table()->FindVrfFromId(pkt_info_->agent_hdr.vrf);
40  if (vrf_ == NULL) {
41  Log("Invalid VRF");
42  return true;
43  }
44 
45  const VmInterface *vm_intf = dynamic_cast<const VmInterface *>(intf_);
46  if (vm_intf == NULL) {
47  Log("Ingress packet on non-VMI interface");
48  return true;
49  }
50  uint32_t vrf_id = 0;
51  if (pkt_info_->agent_hdr.vrf == 0) {
52  vrf_id = vm_intf->vrf_id();
53  } else {
54  vrf_id = pkt_info_->agent_hdr.vrf;
55  }
57  entry_.reset(new MacIpLearningEntry(table_, vrf_id,
58  pkt_info_->ip_saddr,
59  pkt_info_->smac,
60  intf_));
61  if (entry_.get()) {
63  Log("Mac entry added");
64  }
65 
66  return true;
67 }
MacLearningProto * mac_learning_proto() const
Definition: agent.h:1005
InterfaceTable * interface_table() const
Definition: agent.h:465
const string & GetName() const
Definition: vrf.h:100
Agent * agent() const
Definition: proto_handler.h:80
boost::shared_ptr< PktInfo > pkt_info_
Definition: proto_handler.h:92
void Add(MacLearningEntryPtr ptr)
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:884
Definition: agent.h:358
MacIpLearningTable * GetMacIpLearningTable()
uint32_t vrf_id() const
Definition: interface.cc:621
SandeshTraceBufferPtr MacLearningTraceBuf
VrfTable * vrf_table() const
Definition: agent.h:485
const std::string & name() const
Definition: interface.h:114
MacIpLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)