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