OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mac_learning_proto.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <init/agent_param.h>
6 #include "mac_learning_proto.h"
8 #include "mac_learning.h"
9 #include "mac_ip_learning.h"
11 #include "mac_aging.h"
12 
13 MacLearningProto::MacLearningProto(Agent *agent, boost::asio::io_context &io):
14  Proto(agent, kTaskMacLearning, PktHandler::MAC_LEARNING, io),
15  add_tokens_("Add Tokens", this, agent->params()->mac_learning_add_tokens()),
16  change_tokens_("Change tokens", this,
17  agent->params()->mac_learning_update_tokens()),
18  delete_tokens_("Delete tokens", this,
19  agent->params()->mac_learning_delete_tokens()) {
20  Init();
21 }
22 
24 MacLearningProto::AllocProtoHandler(boost::shared_ptr<PktInfo> info,
25  boost::asio::io_context &io) {
26  if (info->agent_hdr.cmd == AgentHdr::TRAP_MAC_IP_LEARNING) {
27  return new MacIpLearningProtoHandler(agent(), info, io);
28  } else {
29  return new MacLearningProtoHandler(agent(), info, io);
30  }
31 }
32 
33 uint32_t MacLearningProto::Hash(uint32_t vrf_id, const MacAddress &mac) {
34  size_t val = 0;
35  uint8_t mac_array[ETH_ALEN];
36 
37  boost::hash_combine(val, vrf_id);
38  mac.ToArray(mac_array, sizeof(mac_array));
39 
40  for (uint32_t i = 0; i < ETH_ALEN; i++) {
41  boost::hash_combine(val, mac_array[i]);
42  }
43 
44  return val % mac_learning_partition_list_.size();
45 }
46 
47 bool
49  //XXXX disable trace ??
50  //FreeBuffer(msg.get());
53 
54  uint32_t table_index = Hash(msg->agent_hdr.vrf, msg->smac);
55  MacLearningPartition* partition = Find(table_index);
56  assert(partition);
57  partition->Enqueue(ptr);
58  return true;
59 }
60 
61 
63  switch(event) {
65  return add_tokens_.GetToken();
66 
68  return change_tokens_.GetToken();
69 
71  return delete_tokens_.GetToken();
72 
73  default:
74  assert(0);
75  }
76 
77  return add_tokens_.GetToken();
78 }
79 
81 MacLearningProto::Find(uint32_t idx) {
82  if (idx >= mac_learning_partition_list_.size()) {
83  assert(0);
84  return NULL;
85  }
86 
87  return mac_learning_partition_list_[idx].get();
88 }
89 
91  pool->IncrementRestarts();
92  for (uint32_t i = 0;
93  i < agent()->params()->mac_learning_thread_count(); i++) {
94  mac_learning_partition_list_[i]->MayBeStartRunner(pool);
95  }
96 }
97 
98 void
100  for (uint32_t i = 0;
101  i < agent()->params()->mac_learning_thread_count(); i++) {
103  mac_learning_partition_list_.push_back(ptr);
104  }
105  mac_ip_learning_tbl_.reset(new MacIpLearningTable(agent(), this));
106 }
108  return mac_ip_learning_tbl_.get();
109 }
bool ToArray(u_int8_t *p, size_t s) const
Definition: mac_address.cc:93
MacIpLearningTablePtr mac_ip_learning_tbl_
MacLearningPartition * Find(uint32_t index)
virtual ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
MacLearningPartitionList mac_learning_partition_list_
Definition: agent.h:358
MacIpLearningTable * GetMacIpLearningTable()
TokenPtr GetToken(MacLearningEntryRequest::Event event)
virtual void TokenAvailable(TokenPool *pool)
bool Enqueue(PktInfoPtr msg)
boost::shared_ptr< MacLearningEntryRequest > MacLearningEntryRequestPtr
AgentParam * params() const
Definition: agent.h:1218
boost::shared_ptr< MacLearningPartition > MacLearningPartitionPtr
virtual TokenPtr GetToken()
Definition: flow_token.cc:41
uint32_t mac_learning_thread_count() const
Definition: agent_param.h:534
boost::shared_ptr< Token > TokenPtr
Definition: flow_token.h:11
uint32_t Hash(uint32_t vrf_id, const MacAddress &mac)
MacLearningProto(Agent *agent, boost::asio::io_context &io)
void IncrementRestarts()
Definition: flow_token.h:34
void Enqueue(MacLearningEntryRequestPtr req)
#define kTaskMacLearning
Definition: agent.h:341
boost::shared_ptr< PktInfo > PktInfoPtr
Definition: pkt_handler.h:61