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"
8 
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 
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  }
58  entry_.reset(new MacIpLearningEntry(table_, vrf_id,
59  pkt_info_->ip_saddr,
60  pkt_info_->smac,
61  intf_));
62  if (entry_.get()) {
64  Log("Mac entry added");
65  }
66 
67  return true;
68 }
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
MacLearningProto * mac_learning_proto() const
Definition: agent.h:1008
VrfTable * vrf_table() const
Definition: agent.h:488
const std::string & name() const
Definition: interface.h:117
uint32_t vrf_id() const
Definition: interface.cc:621
MacIpLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
void Add(MacLearningEntryPtr ptr)
MacIpLearningTable * GetMacIpLearningTable()
Agent * agent() const
Definition: proto_handler.h:81
boost::shared_ptr< PktInfo > pkt_info_
Definition: proto_handler.h:93
const string & GetName() const
Definition: vrf.h:104
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:885
SandeshTraceBufferPtr MacLearningTraceBuf
Definition: io_utils.cc:12