LCOV - code coverage report
Current view: top level - vnsw/agent/vrouter/ksync - ksync_bridge_table.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 23 59 39.0 %
Date: 2026-11-09 02:10:49 Functions: 7 12 58.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      36             : #include "bridge_route_audit_ksync.h"
      37             : #include "sandesh_ksync.h"
      38             : 
      39             : using namespace boost::asio::ip;
      40             : static const uint32_t kTestBridgeTableSize = 65535;
      41             : 
      42           2 : KSyncBridgeMemory::KSyncBridgeMemory(KSync *ksync, uint32_t minor_id):
      43           2 :     KSyncMemory(ksync, minor_id) {
      44           2 :     table_path_ = BRIDGE_TABLE_DEV;
      45           2 : }
      46             : 
      47           4 : KSyncBridgeMemory::~KSyncBridgeMemory() {
      48           4 : }
      49             : 
      50           0 : int KSyncBridgeMemory::EncodeReq(nl_client *cl, uint32_t attr_len) {
      51           0 :     vr_bridge_table_data info;
      52             :     int encode_len, error;
      53             : 
      54           0 :     info.set_btable_op(sandesh_op::GET);
      55           0 :     info.set_btable_size(0);
      56           0 :     info.set_btable_dev(0);
      57           0 :     info.set_btable_file_path("");
      58             : 
      59           0 :     encode_len = info.WriteBinary(nl_get_buf_ptr(cl) + attr_len,
      60             :                                  nl_get_buf_len(cl), &error);
      61           0 :     return encode_len;
      62           0 : }
      63             : 
      64           0 : bool KSyncBridgeMemory::IsInactiveEntry(uint32_t idx, uint8_t &gen_id) {
      65           0 :     vr_bridge_entry* entry = GetBridgeEntry(idx);
      66           0 :     if (entry) {
      67           0 :         const uint16_t &flags = entry->be_flags;
      68           0 :         if (flags & VR_BE_MAC_NEW_FLAG) {
      69           0 :             return true;
      70             :         }
      71             :     }
      72           0 :     return false;
      73             : }
      74             : 
      75           0 : void KSyncBridgeMemory::CreateProtoAuditEntry(uint32_t idx, uint8_t gen_id) {
      76           0 :     if (!IsInactiveEntry(idx, gen_id)) {
      77           0 :         return;
      78             :     }
      79           0 :     vr_bridge_entry* entry = GetBridgeEntry(idx);
      80           0 :     BridgeRouteAuditKSyncObject *obj = ksync_->bridge_route_audit_ksync_obj();
      81           0 :     uint8_t *mac = entry->be_key.be_mac;
      82           0 :     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           0 :     BridgeRouteAuditKSyncEntry key(obj, entry->be_key.be_vrf_id, bmac);
      87           0 :     KSyncEntry *kentry = obj->Create(&key);
      88           0 :     assert(kentry != NULL);
      89             : 
      90             :     //Delete BridgeRouteAuditKSyncEntry to send delete message to Vrouter
      91           0 :     obj->Delete(kentry);
      92           0 : }
      93             : 
      94             : vr_bridge_entry*
      95           0 : KSyncBridgeMemory::GetBridgeEntry(uint32_t idx) {
      96           0 :     if (idx >= table_entries_count_) {
      97           0 :         assert(0);
      98             :     }
      99           0 :     return &bridge_table_[idx];
     100             : }
     101             : 
     102           2 : void KSyncBridgeMemory::InitTest() {
     103           2 :     KSyncSockTypeMap *sock = KSyncSockTypeMap::GetKSyncSockTypeMap();
     104           2 :     table_ = sock->BridgeMmapAlloc(kTestBridgeTableSize);
     105           2 :     table_entries_count_ = kTestBridgeTableSize / get_entry_size();
     106           2 :     audit_yield_ = table_entries_count_;
     107           2 :     audit_timeout_ = 10; // timout immediately.
     108           2 :     SetTableSize();
     109           2 : }
     110             : 
     111           2 : void KSyncBridgeMemory::Shutdown() {
     112           2 :     KSyncSockTypeMap *sock = KSyncSockTypeMap::GetKSyncSockTypeMap();
     113           2 :     sock->BridgeMmapFree();
     114           2 : }
     115             : 
     116           2 : int KSyncBridgeMemory::get_entry_size() {
     117           2 :     return sizeof(vr_bridge_entry);
     118             : }
     119             : 
     120           2 : void KSyncBridgeMemory::SetTableSize() {
     121           2 :     bridge_table_ = static_cast<vr_bridge_entry *>(table_);
     122           2 : }
     123             : 
     124           0 : void vr_bridge_table_data::Process(SandeshContext *context) {
     125           0 :     AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
     126           0 :     ioc->BridgeTableInfoHandler(this);
     127           0 : }

Generated by: LCOV version 1.14