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

Generated by: LCOV version 1.14