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  * 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 MacLearningProtoHandler::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_LEARNING_TRACE(MacLearningTraceBuf, vrf, pkt_info_->smac.ToString(), intf, msg);
29 }
30 
32  const VmInterface *vm_intf = dynamic_cast<const VmInterface *>(intf_);
33  if (vm_intf == NULL) {
34  Log("Ingress packet on non-VMI interface");
35  return;
36  }
37 
38  entry_.reset(new MacLearningEntryLocal(table_, pkt_info_->agent_hdr.vrf,
39  pkt_info_->smac,
40  pkt_info_->agent_hdr.cmd_param,
41  intf_));
42 }
43 
45  const PhysicalInterface *p_intf =
46  dynamic_cast<const PhysicalInterface *>(intf_);
47  if (p_intf == NULL) {
48  Log("Invalid packet on physical interface");
49  return;
50  }
51 
52  if (pkt_info_->pbb_header == NULL) {
53  Log("Non PBB packet on physical interface");
54  return;
55  }
56 
57  std::string bmac_vrf = Agent::NullString();
58  if (vrf_->vn() && vrf_->vn()->GetVrf()) {
59  bmac_vrf = vrf_->vn()->GetVrf()->GetName();
60  }
61 
62  entry_.reset(new MacLearningEntryPBB(table_, pkt_info_->agent_hdr.vrf,
63  pkt_info_->smac,
64  pkt_info_->agent_hdr.cmd_param,
65  pkt_info_->b_smac));
66 }
67 
69  intf_ = agent()->interface_table()->
70  FindInterface(pkt_info_->agent_hdr.ifindex);
71  if (intf_ == NULL) {
72  Log("Invalid interface");
73  return true;
74  }
75 
76  vrf_ = agent()->vrf_table()->FindVrfFromId(pkt_info_->agent_hdr.vrf);
77  if (vrf_ == NULL) {
78  Log("Invalid VRF");
79  return true;
80  }
81 
82  uint32_t table_index = agent()->mac_learning_proto()->Hash(
83  pkt_info_->agent_hdr.vrf, pkt_info_->smac);
84  table_ = agent()->mac_learning_proto()->Find(table_index);
85  if (table_ == NULL) {
86  Log("Mac learning table not found");
87  return true;
88  }
89 
90  if (intf_->type() == Interface::PHYSICAL) {
92  } else {
94  }
95 
96  if (entry_.get()) {
97  table_->Add(entry_);
98  Log("Mac entry added");
99  }
100 
101  return true;
102 }
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
static const std::string & NullString()
Definition: agent.h:440
@ PHYSICAL
Definition: interface.h:32
const std::string & name() const
Definition: interface.h:117
Type type() const
Definition: interface.h:115
void Add(MacLearningEntryPtr ptr)
MacLearningProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
MacLearningPartition * Find(uint32_t index)
uint32_t Hash(uint32_t vrf_id, const MacAddress &mac)
Agent * agent() const
Definition: proto_handler.h:81
boost::shared_ptr< PktInfo > pkt_info_
Definition: proto_handler.h:93
VrfEntry * GetVrf() const
Definition: vn.h:171
const string & GetName() const
Definition: vrf.h:104
VnEntry * vn() const
Definition: vrf.h:105
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:885
SandeshTraceBufferPtr MacLearningTraceBuf
Definition: io_utils.cc:12