LCOV - code coverage report
Current view: top level - bgp/extended-community - mac_mobility.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 22 23 95.7 %
Date: 2026-06-22 02:21:21 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "bgp/extended-community/mac_mobility.h"
       6             : 
       7             : #include <stdio.h>
       8             : 
       9             : #include <algorithm>
      10             : #include <string>
      11             : 
      12             : 
      13             : using std::copy;
      14             : using std::string;
      15             : 
      16         557 : MacMobility::MacMobility(uint32_t seq, bool sticky) {
      17         557 :     data_[0] = BgpExtendedCommunityType::Evpn;
      18         557 :     data_[1] = BgpExtendedCommunityEvpnSubType::MacMobility;
      19         557 :     data_[2] = (sticky ? 0x01 : 0x0);  // sticky
      20         557 :     data_[3] = 0x00; // Reserved
      21         557 :     put_value(&data_[4], 4, seq);
      22         557 : }
      23             : 
      24        7583 : MacMobility::MacMobility(const bytes_type &data) {
      25        7583 :     copy(data.begin(), data.end(), data_.begin());
      26        7583 : }
      27             : 
      28        3266 : bool MacMobility::sticky() const {
      29        3266 :     return (data_[2] & 0x1);
      30             : }
      31             : 
      32        5407 : uint32_t MacMobility::sequence_number() const {
      33             :     uint8_t data[MacMobility::kSize];
      34        5407 :     copy(data_.begin(), data_.end(), &data[0]);
      35        5407 :     if (data[0] == BgpExtendedCommunityType::Evpn &&
      36        5407 :         data[1] == BgpExtendedCommunityEvpnSubType::MacMobility) {
      37        5407 :         uint32_t num = get_value(data + 4, 4);
      38        5407 :         return num;
      39             :     }
      40           0 :     return 0;
      41             : }
      42             : 
      43           7 : std::string MacMobility::ToString() {
      44             :     char temp[50];
      45          14 :     snprintf(temp, sizeof(temp), "mobility:%s:%d",
      46           7 :              (sticky() ? "sticky" : "non-sticky"), sequence_number());
      47           7 :     return string(temp);
      48             : }

Generated by: LCOV version 1.14