OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ksync_bridge_table.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <sys/socket.h>
6 #if defined(__linux__)
7 #include <linux/netlink.h>
8 #endif
9 #include <fcntl.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/ipc.h>
13 #include <sys/shm.h>
14 #include <asm/types.h>
15 #include <boost/asio.hpp>
16 
17 #include <base/timer.h>
18 #include <base/task_trigger.h>
19 #include <base/address_util.h>
20 #include <cmn/agent_cmn.h>
21 #include <ksync/ksync_index.h>
22 #include <ksync/ksync_entry.h>
23 #include <ksync/ksync_object.h>
24 #include <ksync/ksync_netlink.h>
25 #include <ksync/ksync_sock.h>
26 #include <ksync/ksync_sock_user.h>
27 
28 #include <vr_types.h>
29 #include <nl_util.h>
30 #include <vr_bridge.h>
31 #include <vr_genetlink.h>
32 
33 #include "ksync_init.h"
34 #include "ksync_bridge_table.h"
36 #include "sandesh_ksync.h"
37 
38 using namespace boost::asio::ip;
39 static const uint32_t kTestBridgeTableSize = 65535;
40 
41 KSyncBridgeMemory::KSyncBridgeMemory(KSync *ksync, uint32_t minor_id):
42  KSyncMemory(ksync, minor_id) {
43  table_path_ = BRIDGE_TABLE_DEV;
44 }
45 
47 }
48 
49 int KSyncBridgeMemory::EncodeReq(nl_client *cl, uint32_t attr_len) {
50  vr_bridge_table_data info;
51  int encode_len, error;
52 
53  info.set_btable_op(sandesh_op::GET);
54  info.set_btable_size(0);
55  info.set_btable_dev(0);
56  info.set_btable_file_path("");
57 
58  encode_len = info.WriteBinary(nl_get_buf_ptr(cl) + attr_len,
59  nl_get_buf_len(cl), &error);
60  return encode_len;
61 }
62 
63 bool KSyncBridgeMemory::IsInactiveEntry(uint32_t idx, uint8_t &gen_id) {
64  vr_bridge_entry* entry = GetBridgeEntry(idx);
65  if (entry) {
66  const uint16_t &flags = entry->be_flags;
67  if (flags & VR_BE_MAC_NEW_FLAG) {
68  return true;
69  }
70  }
71  return false;
72 }
73 
74 void KSyncBridgeMemory::CreateProtoAuditEntry(uint32_t idx, uint8_t gen_id) {
75  if (!IsInactiveEntry(idx, gen_id)) {
76  return;
77  }
78  vr_bridge_entry* entry = GetBridgeEntry(idx);
80  uint8_t *mac = entry->be_key.be_mac;
81  MacAddress bmac(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
82 
83  //Create a BridgeRouteAuditKSyncEntry. This will NOT send any message to
84  //vrouter
85  BridgeRouteAuditKSyncEntry key(obj, entry->be_key.be_vrf_id, bmac);
86  KSyncEntry *kentry = obj->Create(&key);
87  assert(kentry != NULL);
88 
89  //Delete BridgeRouteAuditKSyncEntry to send delete message to Vrouter
90  obj->Delete(kentry);
91 }
92 
93 vr_bridge_entry*
95  if (idx >= table_entries_count_) {
96  assert(0);
97  }
98  return &bridge_table_[idx];
99 }
100 
106  audit_timeout_ = 10; // timout immediately.
107  SetTableSize();
108 }
109 
112  sock->BridgeMmapFree();
113 }
114 
116  return sizeof(vr_bridge_entry);
117 }
118 
120  bridge_table_ = static_cast<vr_bridge_entry *>(table_);
121 }
122 
123 void vr_bridge_table_data::Process(SandeshContext *context) {
124  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
125  ioc->BridgeTableInfoHandler(this);
126 }
vr_bridge_entry * GetBridgeEntry(uint32_t idx)
virtual void SetTableSize()
virtual void BridgeTableInfoHandler(vr_bridge_table_data *r)
Definition: ksync_sock.h:68
static KSyncSockTypeMap * GetKSyncSockTypeMap()
std::string table_path_
Definition: ksync_memory.h:73
virtual int get_entry_size()
void Delete(KSyncEntry *entry)
uint32_t table_entries_count_
Definition: ksync_memory.h:80
virtual void Shutdown()
uint32_t audit_yield_
Definition: ksync_memory.h:85
virtual void CreateProtoAuditEntry(uint32_t index, uint8_t gen_id)
virtual int EncodeReq(nl_client *nl, uint32_t attr_len)
KSyncBridgeMemory(KSync *ksync, uint32_t minor_id)
void * table_
Definition: ksync_memory.h:71
vr_bridge_entry * BridgeMmapAlloc(int size)
BridgeRouteAuditKSyncObject * bridge_route_audit_ksync_obj() const
Definition: ksync_init.h:78
static const uint32_t kTestBridgeTableSize
uint32_t audit_timeout_
Definition: ksync_memory.h:84
KSyncEntry * Create(const KSyncEntry *key)
virtual bool IsInactiveEntry(uint32_t idx, uint8_t &gen_id)
KSync * ksync_
Definition: ksync_memory.h:70
vr_bridge_entry * bridge_table_
virtual void InitTest()