OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
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 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 
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 
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 
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) {
91  } else {
93  }
94 
95  if (entry_.get()) {
96  table_->Add(entry_);
97  Log("Mac entry added");
98  }
99 
100  return true;
101 }
void Add(MacLearningEntryPtr ptr)
Type type() const
Definition: interface.h:112
MacLearningPartition * Find(uint32_t index)
MacLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
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
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:884
Definition: agent.h:358
SandeshTraceBufferPtr MacLearningTraceBuf
static const std::string & NullString()
Definition: agent.h:437
VrfTable * vrf_table() const
Definition: agent.h:485
VrfEntry * GetVrf() const
Definition: vn.h:170
VnEntry * vn() const
Definition: vrf.h:101
const std::string & name() const
Definition: interface.h:114
uint32_t Hash(uint32_t vrf_id, const MacAddress &mac)